verslag.tex 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. \setcounter{secnumdepth}{1}
  19. \section{Problem description}
  20. License plates are used for uniquely identifying motorized vehicles and are
  21. made to be read by humans from great distances and in all kinds of weather
  22. conditions.
  23. Reading license plates with a computer is much more difficult. Our dataset
  24. contains photographs of license plates from various angles and distances. This
  25. means that not only do we have to implement a method to read the actual
  26. characters, but given the location of the license plate and each individual
  27. character, we must make sure we transform each character to a standard form.
  28. This has to be done or else the local binary patterns will never match!
  29. Determining what character we are looking at will be done by using Local Binary
  30. Patterns. The main goal of our research is finding out how effective LBP's are
  31. in classifying characters on a license plate.
  32. In short our program must be able to do the following:
  33. \begin{enumerate}
  34. \item Use a perspective transformation to obtain an upfront view of license
  35. plate.
  36. \item Reduce noise where possible to ensure maximum readability.
  37. \item Extracting characters using the location points in the xml file.
  38. \item Transforming a character to a normal form.
  39. \item Creating a local binary pattern histogram vector.
  40. \item Matching the found vector with a learning set.
  41. \item And finally it has to check results with a real data set.
  42. \end{enumerate}
  43. \section{Language of choice}
  44. The actual purpose of this project is to check if LBP is capable of recognizing
  45. license plate characters. We knew the LBP implementation would be pretty simple.
  46. Thus an advantage had to be its speed compared with other license plate
  47. recognition implementations, but the uncertainity of whether we could get some
  48. results made us pick Python. We felt Python would not restrict us as much in
  49. assigning tasks to each member of the group. In addition, when using the correct
  50. modules to handle images, Python can be decent in speed.
  51. \section{Implementation}
  52. Now we know what our program has to be capable of, we can start with the
  53. implementations.
  54. \subsection{Transformation}
  55. A simple perspective transformation will be sufficient to transform and resize
  56. the plate to a normalized format. The corner positions of license plates in the
  57. dataset are supplied together with the dataset.
  58. \subsection{Reducing noise}
  59. Small amounts of noise will probably be suppressed by usage of a Gaussian
  60. filter. A real problem occurs in very dirty license plates, where branches and
  61. dirt over a letter could radically change the local binary pattern. A question
  62. we can ask ourselves here, is whether we want to concentrate ourselves on these
  63. exceptional cases. By law, license plates have to be readable. Therefore, we
  64. will first direct our attention at getting a higher score in the 'regular' test
  65. set before addressing these cases. Considered the fact that the LBP algorithm
  66. divides a letter into a lot of cells, there is a good change that a great
  67. number of cells will still match the learning set, and thus still return the
  68. correct character as a best match. Therefore, we expect the algorithm to be
  69. very robust when dealing with noisy images.
  70. \subsection{Extracting a letter}
  71. Because we are already given the locations of the characters, we only need to
  72. transform those locations using the same perspective transformation used to
  73. create a front facing license plate. The next step is to transform the
  74. characters to a normalized manner. The size of the letter W is used as a
  75. standard to normalize the width of all the characters, because W is the widest
  76. character of the alphabet. We plan to also normalize the height of characters,
  77. the best manner for this is still to be determined.
  78. \begin{enumerate}
  79. \item Crop the image in such a way that the character precisely fits the
  80. image.
  81. \item Scale the image to a standard height.
  82. \item Extend the image on either the left or right side to a certain width.
  83. \end{enumerate}
  84. The resulting image will always have the same size, the character contained
  85. will always be of the same height, and the character will alway be positioned
  86. at either the left of right side of the image.
  87. \subsection{Local binary patterns}
  88. Once we have separate digits and characters, we intent to use Local Binary
  89. Patterns (Ojala, Pietikäinen \& Harwood, 1994) to determine what character
  90. or digit we are dealing with. Local Binary
  91. Patters are a way to classify a texture based on the distribution of edge
  92. directions in the image. Since letters on a license plate consist mainly of
  93. straight lines and simple curves, LBP should be suited to identify these.
  94. \subsubsection{LBP Algorithm}
  95. The LBP algorithm that we implemented is a square variant of LBP, the same
  96. that is introduced by Ojala et al (1994). Wikipedia presents a different
  97. form where the pattern is circular.
  98. \begin{itemize}
  99. \item Determine the size of the square where the local patterns are being
  100. registered. For explanation purposes let the square be 3 x 3. \\
  101. \item The grayscale value of the middle pixel is used a threshold. Every value of the pixel
  102. around the middle pixel is evaluated. If it's value is greater than the threshold
  103. it will be become a one else a zero.
  104. \begin{figure}[h!]
  105. \center
  106. \includegraphics[scale=0.5]{lbp.png}
  107. \caption{LBP 3 x 3 (Pietik\"ainen, Hadid, Zhao \& Ahonen (2011))}
  108. \end{figure}
  109. Notice that the pattern will be come of the form 01001110. This is done when a the value
  110. of the evaluated pixel is greater than the threshold, shift the bit by the n(with i=i$_{th}$ pixel
  111. evaluated, starting with $i=0$).
  112. This results in a mathematical expression:
  113. Let I($x_i, y_i$) an Image with grayscale values and $g_n$ the grayscale value of the pixel $(x_i, y_i)$.
  114. Also let $s(g_i - g_c)$ with $g_c$ = grayscale value of the center pixel.
  115. $$
  116. s(v, g_c) = \left\{
  117. \begin{array}{l l}
  118. 1 & \quad \text{if v $\geq$ $g_c$}\\
  119. 0 & \quad \text{if v $<$ $g_c$}\\
  120. \end{array} \right.
  121. $$
  122. $$LBP_{n, g_c = (x_c, y_c)} = \sum\limits_{i=0}^{n-1} s(g_i, g_c)^{2i} $$
  123. The outcome of this operations will be a binary pattern.
  124. \item Given this pattern, the next step is to divide the pattern in cells. The
  125. amount of cells depends on the quality of the result, so trial and error is in order.
  126. Starting with dividing the pattern in to 16 cells.
  127. \item Compute a histogram for each cell.
  128. \begin{figure}[h!]
  129. \center
  130. \includegraphics[scale=0.7]{cells.png}
  131. \caption{Divide in cells(Pietik\"ainen et all (2011))}
  132. \end{figure}
  133. \item Consider every histogram as a vector element and concatenate these. The result is a
  134. feature vector of the image.
  135. \item Feed these vectors to a support vector machine. This will ''learn'' which vector
  136. are.
  137. \end{itemize}
  138. To our knowledge, LBP has yet not been used in this manner before. Therefore,
  139. it will be the first thing to implement, to see if it lives up to the
  140. expectations. When the proof of concept is there, it can be used in the final
  141. program.
  142. Important to note is that due to the normalization of characters before
  143. applying LBP. Therefore, no further normalization is needed on the histograms.
  144. Given the LBP of a character, a Support Vector Machine can be used to classify
  145. the character to a character in a learning set. The SVM uses
  146. \subsection{Matching the database}
  147. Given the LBP of a character, a Support Vector Machine can be used to classify
  148. the character to a character in a learning set. The SVM uses the collection of
  149. histograms of an image as a feature vector. The SVM can be trained with a
  150. subsection 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{Licenseplate retrieval}
  157. In order to retrieve the license plate 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 the licenseplate. 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 which country the
  164. plate is from. The reader is currently assuming the XML file and image name are corresponding. Since this was the case
  165. for the given dataset. This can easily be adjusted if required.
  166. To parse the XML file, the minidom module is used. So the XML file can be
  167. treated as a tree, where one can search for certain nodes. In each XML
  168. file it is possible that multiple versions exist, so the first thing the reader will do is
  169. retrieve the current and most up-to-date version of the plate. The reader will only get results from this
  170. version.
  171. Now we are only interested in the individual characters so we can skip the location
  172. of the entire license plate. Each character has
  173. a single character value, indicating what someone thought what the letter or digit was and four coordinates to create
  174. a bounding box. To make things not to complicated a
  175. Character class and Point class are used. They
  176. act pretty much as associative lists, but it gives extra freedom on using the
  177. data. If less then four points have been set the character will not be saved.
  178. When four points have been gathered the data from the actual image is being requested.
  179. For each corner a small margin is added (around 3 pixels) so that no features will be lost and minimum
  180. amounts of new features will be introduced by noise in the margin.
  181. In the next section you can read more about the perspective transformation that is being done. After the transformation the
  182. character can be saved: Converted to grayscale, but nothing further. This was used
  183. to create a learning set. If it doesn't need to be saved as an actual image it will be converted
  184. to a NormalizedImage. When these actions have been completed for each character the license
  185. plate is usable in the rest of the code.
  186. \paragraph*{Perspective transformation}
  187. Once we retrieved the cornerpoints of the license plate, we feed those to a
  188. module that extracts the (warped) license plate from the original image, and
  189. creates a new image where the license plate is cut out, and is transformed to a
  190. rectangle.
  191. \subsection{Noise reduction}
  192. The image contains a lot of noise, both from camera errors due to dark noise
  193. etc., as from dirt on the license plate. In this case, noise therefore means
  194. any unwanted difference in color from the surrounding pixels.
  195. \paragraph*{Camera noise and small amounts of dirt}
  196. The dirt on the license plate can be of different sizes. We can reduce the
  197. smaller amounts of dirt in the same way as we reduce normal noise, by applying
  198. a Gaussian blur to the image. This is the next step in our program.\\
  199. \\
  200. The Gaussian filter we use comes from the \texttt{scipy.ndimage} module. We use
  201. this function instead of our own function, because the standard functions are
  202. most likely more optimized then our own implementation, and speed is an
  203. important factor in this application.
  204. \paragraph*{Larger amounts of dirt}
  205. Larger amounts of dirt are not going to be resolved by using a Gaussian filter.
  206. We rely on one of the characteristics of the Local Binary Pattern, only looking
  207. at the difference between two pixels, to take care of these problems.\\
  208. Because there will probably always be a difference between the characters and
  209. the dirt, and the fact that the characters are very black, the shape of the
  210. characters will still be conserved in the LBP, even if there is dirt
  211. surrounding the character.
  212. \subsection{Character retrieval}
  213. The retrieval of the character is done the same as the retrieval of the license
  214. plate, by using a perspective transformation. The location of the characters on
  215. the license plate is also available in de XML file, so this is parsed from that
  216. as well.
  217. \subsection{Creating Local Binary Patterns and feature vector}
  218. \subsection{Classification}
  219. \section{Finding parameters}
  220. Now that we have a functioning system, we need to tune it to work properly for
  221. license plates. This means we need to find the parameters. Throughout the
  222. program we have a number of parameters for which no standard choice is
  223. available. These parameters are:\\
  224. \\
  225. \begin{tabular}{l|l}
  226. Parameter & Description\\
  227. \hline
  228. $\sigma$ & The size of the Gaussian blur.\\
  229. \emph{cell size} & The size of a cell for which a histogram of LBPs will
  230. be generated.\\
  231. $\gamma$ & Parameter for the Radial kernel used in the SVM.\\
  232. $c$ & The soft margin of the SVM. Allows how much training
  233. errors are accepted.
  234. \end{tabular}\\
  235. \\
  236. For each of these parameters, we will describe how we searched for a good
  237. value, and what value we decided on.
  238. \subsection{Parameter $\sigma$}
  239. The first parameter to decide on, is the $\sigma$ used in the Gaussian blur. To
  240. find this parameter, we tested a few values, by checking visually what value
  241. removed most noise out of the image, while keeping the edges sharp enough to
  242. work with. By checking in the neighbourhood of the value that performed best,
  243. we where able to 'zoom in' on what we thought was the best value. It turned out
  244. that this was $\sigma = ?$.
  245. \subsection{Parameter \emph{cell size}}
  246. The cell size of the Local Binary Patterns determines over what region a
  247. histogram is made. The trade-off here is that a bigger cell size makes the
  248. classification less affected by relative movement of a character compared to
  249. those in the learning set, since the important structure will be more likely to
  250. remain in the same cell. However, if the cell size is too big, there will not
  251. be enough cells to properly describe the different areas of the character, and
  252. the feature vectors will not have enough elements.\\
  253. \\
  254. In order to find this parameter, we used a trial-and-error technique on a few
  255. basic cell sizes, being ?, 16, ?. We found that the best result was reached by
  256. using ??.
  257. \subsection{Parameters $\gamma$ \& $c$}
  258. The parameters $\gamma$ and $c$ are used for the SVM. $c$ is a standard
  259. parameter for each type of SVM, called the 'soft margin'. This indicates how
  260. exact each element in the learning set should be taken. A large soft margin
  261. means that an element in the learning set that accidentally has a completely
  262. different feature vector than expected, due to noise for example, is not taken
  263. into account. If the soft margin is very small, then almost all vectors will be
  264. taken into account, unless they differ extreme amounts.\\
  265. $\gamma$ is a variable that determines the size of the radial kernel, and as
  266. such blablabla.\\
  267. \\
  268. Since these parameters both influence the SVM, we need to find the best
  269. combination of values. To do this, we perform a so-called grid-search. A
  270. grid-search takes exponentially growing sequences for each parameter, and
  271. checks for each combination of values what the score is. The combination with
  272. the highest score is then used as our parameters, and the entire SVM will be
  273. trained using those parameters.\\
  274. \\
  275. We found that the best values for these parameters are $c=?$ and $\gamma =?$.
  276. \section{Results}
  277. The goal was to find out two things with this research: The speed of the
  278. classification and the accuracy. In this section we will show our findings.
  279. \subsection{Speed}
  280. Recognizing license plates is something that has to be done fast, since there
  281. can be a lot of cars passing a camera in a short time, especially on a highway.
  282. Therefore, we measured how well our program performed in terms of speed. We
  283. measure the time used to classify a license plate, not the training of the
  284. dataset, since that can be done offline, and speed is not a primary necessity
  285. there.\\
  286. \\
  287. The speed of a classification turned out to be blablabla.
  288. \subsection{Accuracy}
  289. Of course, it is vital that the recognition of a license plate is correct,
  290. almost correct is not good enough here. Therefore, we have to get the highest
  291. accuracy score we possibly can.\\
  292. \\ According to Wikipedia
  293. \footnote{
  294. \url{http://en.wikipedia.org/wiki/Automatic_number_plate_recognition}},
  295. commercial license plate recognition software score about $90\%$ to $94\%$,
  296. under optimal conditions and with modern equipment. Our program scores an
  297. average of blablabla.
  298. \section{Workload distribution}
  299. The first two weeks were team based. Basically the LBP algorithm could be
  300. implemented in the first hour, while some talked and someone did the typing.
  301. Some additional 'basics' where created in similar fashion. This ensured that
  302. every team member was up-to-date and could start figuring out which part of the
  303. implementation was most suited to be done by one individually or in a pair.
  304. \subsection{Who did what}
  305. Gijs created the basic classes we could use and helped the rest everyone by
  306. keeping track of what required to be finished and whom was working on what.
  307. Tadde\"us and Jayke were mostly working on the SVM and all kinds of tests
  308. whether the histograms were mathing and alike. Fabi\"en created the functions
  309. to read and parse the given xml files with information about the license plates.
  310. Upon completion all kinds of learning and data sets could be created.
  311. %Richard je moet even toevoegen wat je hebt gedaan :P:P
  312. %maar miss is dit hele ding wel overbodig. Ik dacht dat Rein het zei tijdens gesprek van ik wil weten
  313. %hoe het ging enzo
  314. \subsection{How it went}
  315. Sometimes one cannot hear the alarm bell and wake up properly. This however was
  316. not a big problem as no one was affraid of staying at Science Park a bit longer
  317. to help out. Further communication usually went through e-mails and replies
  318. were instantaneous! A crew to remember.
  319. \section{Conclusion}
  320. Awesome
  321. \end{document}