report.tex 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. \documentclass[a4paper]{article}
  2. \usepackage{amsmath}
  3. \usepackage{hyperref}
  4. \usepackage{graphicx}
  5. \title{Using local binary patterns to read license plates in photographs}
  6. % Paragraph indentation
  7. \setlength{\parindent}{0pt}
  8. \setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
  9. \begin{document}
  10. \maketitle
  11. \section*{Project members}
  12. Gijs van der Voort\\
  13. Richard Torenvliet\\
  14. Jayke Meijer\\
  15. Tadde\"us Kroes\\
  16. Fabi\'en Tesselaar
  17. \tableofcontents
  18. \pagebreak
  19. \setcounter{secnumdepth}{1}
  20. \section{Problem description}
  21. License plates are used for uniquely identifying motorized vehicles and are
  22. made to be read by humans from great distances and in all kinds of weather
  23. conditions.
  24. Reading license plates with a computer is much more difficult. Our dataset
  25. contains photographs of license plates from various angles and distances. This
  26. means that not only do we have to implement a method to read the actual
  27. characters, but given the location of the license plate and each individual
  28. character, we must make sure we transform each character to a standard form.
  29. This has to be done or else the local binary patterns will never match!
  30. Determining what character we are looking at will be done by using Local Binary
  31. Patterns. The main goal of our research is finding out how effective LBP's are
  32. in classifying characters on a license plate.
  33. In short our program must be able to do the following:
  34. \begin{enumerate}
  35. \item Extracting characters using the location points in the xml file.
  36. \item Reduce noise where possible to ensure maximum readability.
  37. \item Transforming a character to a normal form.
  38. \item Creating a local binary pattern histogram vector.
  39. \item Matching the found vector with a learning set.
  40. \item And finally it has to check results with a real data set.
  41. \end{enumerate}
  42. \section{Language of choice}
  43. The actual purpose of this project is to check if LBP is capable of recognizing
  44. license plate characters. We knew the LBP implementation would be pretty
  45. simple. Thus an advantage had to be its speed compared with other license plate
  46. recognition implementations, but the uncertainty of whether we could get some
  47. results made us pick Python. We felt Python would not restrict us as much in
  48. assigning tasks to each member of the group. In addition, when using the
  49. correct modules to handle images, Python can be decent in speed.
  50. \section{Theory}
  51. Now we know what our program has to be capable of, we can start with the
  52. defining what problems we have and how we want to solve these.
  53. \subsection{Extracting a letter}
  54. Rewrite this section once we have implemented this properly.
  55. %NO LONGER VALID!
  56. %Because we are already given the locations of the characters, we only need to
  57. %transform those locations using the same perspective transformation used to
  58. %create a front facing license plate. The next step is to transform the
  59. %characters to a normalized manner. The size of the letter W is used as a
  60. %standard to normalize the width of all the characters, because W is the widest
  61. %character of the alphabet. We plan to also normalize the height of characters,
  62. %the best manner for this is still to be determined.
  63. %\begin{enumerate}
  64. % \item Crop the image in such a way that the character precisely fits the
  65. % image.
  66. % \item Scale the image to a standard height.
  67. % \item Extend the image on either the left or right side to a certain width.
  68. %\end{enumerate}
  69. %The resulting image will always have the same size, the character contained
  70. %will always be of the same height, and the character will always be positioned
  71. %at either the left of right side of the image.
  72. \subsection{Transformation}
  73. A simple perspective transformation will be sufficient to transform and resize
  74. the characters to a normalized format. The corner positions of characters in
  75. the dataset are supplied together with the dataset.
  76. \subsection{Reducing noise}
  77. Small amounts of noise will probably be suppressed by usage of a Gaussian
  78. filter. A real problem occurs in very dirty license plates, where branches and
  79. dirt over a letter could radically change the local binary pattern. A question
  80. we can ask ourselves here, is whether we want to concentrate ourselves on these
  81. exceptional cases. By law, license plates have to be readable. However, the
  82. provided dataset showed that this does not means they always are. We will have
  83. to see how the algorithm performs on these plates, however we have good hopes
  84. that our method will get a good score on dirty plates, as long as a big enough
  85. part of the license plate remains readable.
  86. \subsection{Local binary patterns}
  87. Once we have separate digits and characters, we intent to use Local Binary
  88. Patterns (Ojala, Pietikäinen \& Harwood, 1994) to determine what character
  89. or digit we are dealing with. Local Binary
  90. Patterns are a way to classify a texture based on the distribution of edge
  91. directions in the image. Since letters on a license plate consist mainly of
  92. straight lines and simple curves, LBP should be suited to identify these.
  93. \subsubsection{LBP Algorithm}
  94. The LBP algorithm that we implemented is a square variant of LBP, the same
  95. that is introduced by Ojala et al (1994). Wikipedia presents a different
  96. form where the pattern is circular.
  97. \begin{itemize}
  98. \item Determine the size of the square where the local patterns are being
  99. registered. For explanation purposes let the square be 3 x 3. \\
  100. \item The grayscale value of the middle pixel is used as threshold. Every
  101. value of the pixel around the middle pixel is evaluated. If it's value is
  102. greater than the threshold it will be become a one else a zero.
  103. \begin{figure}[h!]
  104. \center
  105. \includegraphics[scale=0.5]{lbp.png}
  106. \caption{LBP 3 x 3 (Pietik\"ainen, Hadid, Zhao \& Ahonen (2011))}
  107. \end{figure}
  108. Notice that the pattern will be come of the form 01001110. This is done when a
  109. the value of the evaluated pixel is greater than the threshold, shift the bit
  110. by the n(with i=i$_{th}$ pixel evaluated, starting with $i=0$).
  111. This results in a mathematical expression:
  112. Let I($x_i, y_i$) an Image with grayscale values and $g_n$ the grayscale value
  113. of the pixel $(x_i, y_i)$. Also let $s(g_i, g_c)$ (see below) with $g_c$ =
  114. grayscale value of the center pixel and $g_i$ the grayscale value of the pixel
  115. to be evaluated.
  116. $$
  117. s(g_i, g_c) = \left\{
  118. \begin{array}{l l}
  119. 1 & \quad \text{if $g_i$ $\geq$ $g_c$}\\
  120. 0 & \quad \text{if $g_i$ $<$ $g_c$}\\
  121. \end{array} \right.
  122. $$
  123. $$LBP_{n, g_c = (x_c, y_c)} = \sum\limits_{i=0}^{n-1} s(g_i, g_c)^{2i} $$
  124. The outcome of this operations will be a binary pattern.
  125. \item Given this pattern, the next step is to divide the pattern in cells. The
  126. amount of cells depends on the quality of the result, so trial and error is in
  127. order. Starting with dividing the pattern in to cells of size 16.
  128. \item Compute a histogram for each cell.
  129. \begin{figure}[h!]
  130. \center
  131. \includegraphics[scale=0.7]{cells.png}
  132. \caption{Divide in cells(Pietik\"ainen et all (2011))}
  133. \end{figure}
  134. \item Consider every histogram as a vector element and concatenate these. The
  135. result is a feature vector of the image.
  136. \item Feed these vectors to a support vector machine. This will ''learn'' which
  137. vector indicates what vector is which character.
  138. \end{itemize}
  139. To our knowledge, LBP has yet not been used in this manner before. Therefore,
  140. it will be the first thing to implement, to see if it lives up to the
  141. expectations. When the proof of concept is there, it can be used in a final
  142. program.
  143. Later we will show that taking a histogram over the entire image (basically
  144. working with just one cell) gives us the best results.
  145. \subsection{Matching the database}
  146. Given the LBP of a character, a Support Vector Machine can be used to classify
  147. the character to a character in a learning set. The SVM uses a concatenation
  148. of each cell in an image as a feature vector (in the case we check the entire
  149. image no concatenation has to be done of course. The SVM can be trained with a
  150. subset of the given dataset called the ''Learning set''. Once trained, the
  151. entire classifier can be saved as a Pickle object\footnote{See
  152. \url{http://docs.python.org/library/pickle.html}} for later usage.
  153. \section{Implementation}
  154. In this section we will describe our implementations in more detail, explaining
  155. choices we made.
  156. \subsection{Character retrieval}
  157. In order to retrieve the characters from the entire image, we need to
  158. perform a perspective transformation. However, to do this, we need to know the
  159. coordinates of the four corners of each character. For our dataset, this is
  160. stored in XML files. So, the first step is to read these XML files.
  161. \paragraph*{XML reader}
  162. The XML reader will return a 'license plate' object when given an XML file. The
  163. licence plate holds a list of, up to six, NormalizedImage characters and from
  164. which country the plate is from. The reader is currently assuming the XML file
  165. and image name are corresponding. Since this was the case for the given
  166. dataset. This can easily be adjusted if required.
  167. To parse the XML file, the minidom module is used. So the XML file can be
  168. treated as a tree, where one can search for certain nodes. In each XML
  169. file it is possible that multiple versions exist, so the first thing the reader
  170. will do is retrieve the current and most up-to-date version of the plate. The
  171. reader will only get results from this version.
  172. Now we are only interested in the individual characters so we can skip the
  173. location of the entire license plate. Each character has
  174. a single character value, indicating what someone thought what the letter or
  175. digit was and four coordinates to create a bounding box. To make things not to
  176. complicated a Character class and Point class are used. They
  177. act pretty much as associative lists, but it gives extra freedom on using the
  178. data. If less then four points have been set the character will not be saved.
  179. When four points have been gathered the data from the actual image is being
  180. requested. For each corner a small margin is added (around 3 pixels) so that no
  181. features will be lost and minimum amounts of new features will be introduced by
  182. noise in the margin.
  183. In the next section you can read more about the perspective transformation that
  184. is being done. After the transformation the character can be saved: Converted
  185. to grayscale, but nothing further. This was used to create a learning set. If
  186. it does not need to be saved as an actual image it will be converted to a
  187. NormalizedImage. When these actions have been completed for each character the
  188. license plate is usable in the rest of the code.
  189. \paragraph*{Perspective transformation}
  190. Once we retrieved the corner points of the character, we feed those to a
  191. module that extracts the (warped) character from the original image, and
  192. creates a new image where the character is cut out, and is transformed to a
  193. rectangle.
  194. \subsection{Noise reduction}
  195. The image contains a lot of noise, both from camera errors due to dark noise
  196. etc., as from dirt on the license plate. In this case, noise therefore means
  197. any unwanted difference in color from the surrounding pixels.
  198. \paragraph*{Camera noise and small amounts of dirt}
  199. The dirt on the license plate can be of different sizes. We can reduce the
  200. smaller amounts of dirt in the same way as we reduce normal noise, by applying
  201. a Gaussian blur to the image. This is the next step in our program.\\
  202. \\
  203. The Gaussian filter we use comes from the \texttt{scipy.ndimage} module. We use
  204. this function instead of our own function, because the standard functions are
  205. most likely more optimized then our own implementation, and speed is an
  206. important factor in this application.
  207. \paragraph*{Larger amounts of dirt}
  208. Larger amounts of dirt are not going to be resolved by using a Gaussian filter.
  209. We rely on one of the characteristics of the Local Binary Pattern, only looking
  210. at the difference between two pixels, to take care of these problems.\\
  211. Because there will probably always be a difference between the characters and
  212. the dirt, and the fact that the characters are very black, the shape of the
  213. characters will still be conserved in the LBP, even if there is dirt
  214. surrounding the character.
  215. \subsection{Creating Local Binary Patterns and feature vector}
  216. Every pixel is a center pixel and it is also a value to evaluate but not at the
  217. same time. Every pixel is evaluated as shown in the explanation
  218. of the LBP algorithm. There are several neighbourhoods we can evaluate. We have
  219. tried the following neighbourhoods:
  220. \begin{figure}[h!]
  221. \center
  222. \includegraphics[scale=0.5]{neighbourhoods.png}
  223. \caption{Tested neighbourhoods}
  224. \end{figure}
  225. We chose these neighbourhoods to prevent having to use interpolation, which
  226. would add a computational step, thus making the code execute slower. In the
  227. next section we will describe what the best neighbourhood was.
  228. Take an example where the
  229. full square can be evaluated, there are cases where the neighbours are out of
  230. bounds. The first to be checked is the pixel in the left
  231. bottom corner in the square 3 x 3, with coordinate $(x - 1, y - 1)$ with $g_c$
  232. as center pixel that has coordinates $(x, y)$. If the grayscale value of the
  233. neighbour in the left corner is greater than the grayscale
  234. value of the center pixel than return true. Bit-shift the first bit with 7. The
  235. outcome is now 1000000. The second neighbour will be bit-shifted with 6, and so
  236. on. Until we are at 0. The result is a binary pattern of the local point just
  237. evaluated.
  238. Now only the edge pixels are a problem, but a simple check if the location of
  239. the neighbour is still in the image can resolve this. We simply return false if
  240. it is.
  241. \paragraph*{Histogram and Feature Vector}
  242. After all the Local Binary Patterns are created for every pixel. This pattern
  243. is divided in to cells. The feature vector is the vector of concatenated
  244. histograms. These histograms are created for cells. These cells are created by
  245. dividing the \textbf{pattern} in to cells and create a histogram of that. So
  246. multiple cells are related to one histogram. All the histograms are
  247. concatenated and fed to the SVM that will be discussed in the next section,
  248. Classification. We did however find out that the use of several cells was not
  249. increasing our performance, so we only have one histogram to feed to the SVM.
  250. \subsection{Classification}
  251. \section{Finding parameters}
  252. Now that we have a functioning system, we need to tune it to work properly for
  253. license plates. This means we need to find the parameters. Throughout the
  254. program we have a number of parameters for which no standard choice is
  255. available. These parameters are:\\
  256. \\
  257. \begin{tabular}{l|l}
  258. Parameter & Description\\
  259. \hline
  260. $\sigma$ & The size of the Gaussian blur.\\
  261. \emph{cell size} & The size of a cell for which a histogram of LBP's
  262. will be generated.\\
  263. \emph{Neighbourhood}& The neighbourhood to use for creating the LBP.\\
  264. $\gamma$ & Parameter for the Radial kernel used in the SVM.\\
  265. $c$ & The soft margin of the SVM. Allows how much training
  266. errors are accepted.\\
  267. \end{tabular}\\
  268. \\
  269. For each of these parameters, we will describe how we searched for a good
  270. value, and what value we decided on.
  271. \subsection{Parameter $\sigma$}
  272. The first parameter to decide on, is the $\sigma$ used in the Gaussian blur. To
  273. find this parameter, we tested a few values, by checking visually what value
  274. removed most noise out of the image, while keeping the edges sharp enough to
  275. work with. It turned out the best value is $\sigma = 0.5$.
  276. \subsection{Parameter \emph{cell size}}
  277. The cell size of the Local Binary Patterns determines over what region a
  278. histogram is made. The trade-off here is that a bigger cell size makes the
  279. classification less affected by relative movement of a character compared to
  280. those in the learning set, since the important structure will be more likely to
  281. remain in the same cell. However, if the cell size is too big, there will not
  282. be enough cells to properly describe the different areas of the character, and
  283. the feature vectors will not have enough elements.\\
  284. \\
  285. In order to find this parameter, we used a trial-and-error technique on a few
  286. cell sizes. During this testing, we discovered that a lot better score was
  287. reached when we take the histogram over the entire image, so with a single
  288. cell. Therefore, we decided to work without cells.\\
  289. \\
  290. The reason that using one cell works best is probably because the size of a
  291. single character on a license plate in the provided dataset is very small.
  292. That means that when dividing it into cells, these cells become simply too
  293. small to have a really representative histogram. Therefore, the
  294. concatenated histograms are then a list of only very small numbers, which
  295. are not significant enough to allow for reliable classification.
  296. \subsection{Parameter \emph{Neighbourhood}}
  297. The neighbourhood to use can only be determined through testing. We did a test
  298. with each of these neighbourhoods, and we found that the best results were
  299. reached with the following neighbourhood, which we will call the
  300. ()-neighbourhood.
  301. \subsection{Parameters $\gamma$ \& $c$}
  302. The parameters $\gamma$ and $c$ are used for the SVM. $c$ is a standard
  303. parameter for each type of SVM, called the 'soft margin'. This indicates how
  304. exact each element in the learning set should be taken. A large soft margin
  305. means that an element in the learning set that accidentally has a completely
  306. different feature vector than expected, due to noise for example, is not taken
  307. into account. If the soft margin is very small, then almost all vectors will be
  308. taken into account, unless they differ extreme amounts.\\
  309. $\gamma$ is a variable that determines the size of the radial kernel, and as
  310. such determines how steep the difference between two classes can be.\\
  311. \\
  312. Since these parameters both influence the SVM, we need to find the best
  313. combination of values. To do this, we perform a so-called grid-search. A
  314. grid-search takes exponentially growing sequences for each parameter, and
  315. checks for each combination of values what the score is. The combination with
  316. the highest score is then used as our parameters, and the entire SVM will be
  317. trained using those parameters.\\
  318. \\
  319. We found that the best values for these parameters are $c = ?$ and
  320. $\gamma = ?$.
  321. \section{Results}
  322. The goal was to find out two things with this research: The speed of the
  323. classification and the accuracy. In this section we will show our findings.
  324. \subsection{Speed}
  325. Recognizing license plates is something that has to be done fast, since there
  326. can be a lot of cars passing a camera in a short time, especially on a highway.
  327. Therefore, we measured how well our program performed in terms of speed. We
  328. measure the time used to classify a license plate, not the training of the
  329. dataset, since that can be done offline, and speed is not a primary necessity
  330. there.\\
  331. \\
  332. The speed of a classification turned out to be ???.
  333. \subsection{Accuracy}
  334. Of course, it is vital that the recognition of a license plate is correct,
  335. almost correct is not good enough here. Therefore, we have to get the highest
  336. accuracy score we possibly can.\\
  337. \\ According to Wikipedia
  338. \footnote{
  339. \url{http://en.wikipedia.org/wiki/Automatic_number_plate_recognition}},
  340. commercial license plate recognition software score about $90\%$ to $94\%$,
  341. under optimal conditions and with modern equipment. Our program scores an
  342. average of ???.
  343. \section{Conclusion}
  344. In the end it turns out that using Local Binary Patterns is a promising
  345. technique for License Plate Recognition. It seems to be relatively unfased by
  346. dirty licenseplates and different fonts on these plates.\\
  347. \\
  348. The performance speedwise is ???
  349. \section{Reflection}
  350. \subsection{Difficulties}
  351. During the implementation and testing of the program, we did encounter a
  352. number of difficulties. In this section we will state what these difficulties
  353. were and whether we were able to find a proper solution for them.
  354. \subsubsection*{Dataset}
  355. We did experience a number of problems with the provided dataset. A number of
  356. these are problems to be expected in a real world problem, but which make
  357. development harder. Others are more elemental problems.\\
  358. The first problem was that the dataset contains a lot of license plates which
  359. are problematic to read, due to excessive amounts of dirt on them. Of course,
  360. this is something you would encounter in the real situation, but it made it
  361. hard for us to see whether there was a coding error or just a bad example.\\
  362. Another problem was that there were license plates of several countries in
  363. the dataset. Each of these countries has it own font, which also makes it
  364. hard to identify these plates, unless there are a lot of these plates in the
  365. learning set.\\
  366. A problem that is more elemental is that some of the characters in the dataset
  367. are not properly classified. This is of course very problematic, both for
  368. training the SVM as for checking the performance. This meant we had to check
  369. each character whether its description was correct.
  370. \subsubsection*{SVM}
  371. We also had trouble with the SVM for Python. The standard Python SVM, libsvm,
  372. had a poor documentation. There was no explanation what so ever on which
  373. parameter had to be what. This made it a lot harder for us to see what went
  374. wrong in the program.
  375. \subsection{Workload distribution}
  376. The first two weeks were team based. Basically the LBP algorithm could be
  377. implemented in the first hour, while some talked and someone did the typing.
  378. Some additional 'basics' where created in similar fashion. This ensured that
  379. every team member was up-to-date and could start figuring out which part of the
  380. implementation was most suited to be done by one individually or in a pair.
  381. \subsubsection*{Who did what}
  382. Gijs created the basic classes we could use and helped the rest everyone by
  383. keeping track of what required to be finished and whom was working on what.
  384. Tadde\"us and Jayke were mostly working on the SVM and all kinds of tests
  385. whether the histograms were matching and alike. Fabi\"en created the functions
  386. to read and parse the given xml files with information about the license
  387. plates. Upon completion all kinds of learning and data sets could be created.
  388. %Richard je moet even toevoegen wat je hebt gedaan :P:P
  389. %maar miss is dit hele ding wel overbodig Ik dacht dat Rein het zei tijdens
  390. %gesprek van ik wil weten hoe het ging enzo.
  391. \subsubsection*{How it went}
  392. Sometimes one cannot hear the alarm bell and wake up properly. This however was
  393. not a big problem as no one was afraid of staying at Science Park a bit longer
  394. to help out. Further communication usually went through e-mails and replies
  395. were instantaneous! A crew to remember.
  396. \end{document}