verslag.tex 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 also have to determine the location of the license plate and
  27. its transformation due to different angles.
  28. We will focus our research on reading the transformed characters on the
  29. license plate, of which we know where the letters are located. This is because
  30. Microsoft recently published a new and effective method to find the location of
  31. text in an image.
  32. Determining what character we are looking at will be done by using Local Binary
  33. Patterns. The main goal of our research is finding out how effective LBP's are
  34. in classifying characters on a license plate.
  35. In short our program must be able to do the following:
  36. \begin{enumerate}
  37. \item Use perspective transformation to obtain an upfront view of license
  38. plate.
  39. \item Reduce noise where possible.
  40. \item Extract each character using the location points in the info file.
  41. \item Transform character to a normal form.
  42. \item Create a local binary pattern histogram vector.
  43. \item Match the found vector with a learning set.
  44. \end{enumerate}
  45. \section{Solutions}
  46. Now that the problem is defined, the next step is stating our basic solutions.
  47. This will come in a few steps as well.
  48. \subsection{Transformation}
  49. A simple perspective transformation will be sufficient to transform and resize
  50. the plate to a normalized format. The corner positions of license plates in the
  51. dataset are supplied together with the dataset.
  52. \subsection{Reducing noise}
  53. Small amounts of noise will probably be suppressed by usage of a Gaussian
  54. filter. A real problem occurs in very dirty license plates, where branches and
  55. dirt over a letter could radically change the local binary pattern. A question
  56. we can ask ourselves here, is whether we want to concentrate ourselves on these
  57. exceptional cases. By law, license plates have to be readable. Therefore, we
  58. will first direct our attention at getting a higher score in the 'regular' test
  59. set before addressing these cases. Considered the fact that the LBP algorithm
  60. divides a letter into a lot of cells, there is a good change that a great
  61. number of cells will still match the learning set, and thus still return the
  62. correct character as a best match. Therefore, we expect the algorithm to be
  63. very robust when dealing with noisy images.
  64. \subsection{Extracting a letter}
  65. Because we are already given the locations of the characters, we only need to
  66. transform those locations using the same perspective transformation used to
  67. create a front facing license plate. The next step is to transform the
  68. characters to a normalized manner. The size of the letter W is used as a
  69. standard to normalize the width of all the characters, because W is the widest
  70. character of the alphabet. We plan to also normalize the height of characters,
  71. the best manner for this is still to be determined.
  72. \begin{enumerate}
  73. \item Crop the image in such a way that the character precisely fits the
  74. image.
  75. \item Scale the image to a standard height.
  76. \item Extend the image on either the left or right side to a certain width.
  77. \end{enumerate}
  78. The resulting image will always have the same size, the character contained
  79. will always be of the same height, and the character will alway be positioned
  80. at either the left of right side of the image.
  81. \subsection{Local binary patterns}
  82. Once we have separate digits and characters, we intent to use Local Binary
  83. Patterns (Ojala, Pietikäinen \& Harwood, 1994) to determine what character
  84. or digit we are dealing with. Local Binary
  85. Patters are a way to classify a texture based on the distribution of edge
  86. directions in the image. Since letters on a license plate consist mainly of
  87. straight lines and simple curves, LBP should be suited to identify these.
  88. \subsubsection{LBP Algorithm}
  89. The LBP algorithm that we implemented is a square variant of LBP, the same
  90. that is introduced by Ojala et al (1994). Wikipedia presents a different
  91. form where the pattern is circular.
  92. \begin{itemize}
  93. \item Determine the size of the square where the local patterns are being
  94. registered. For explanation purposes let the square be 3 x 3. \\
  95. \item The grayscale value of the middle pixel is used a threshold. Every value of the pixel
  96. around the middle pixel is evaluated. If it's value is greater than the threshold
  97. it will be become a one else a zero.
  98. \begin{figure}[h!]
  99. \center
  100. \includegraphics[scale=0.5]{lbp.png}
  101. \caption{LBP 3 x 3 (Pietik\"ainen, Hadid, Zhao \& Ahonen (2011))}
  102. \end{figure}
  103. Notice that the pattern will be come of the form 01001110. This is done when a the value
  104. of the evaluated pixel is greater than the threshold, shift the bit by the n(with i=i$_{th}$ pixel
  105. evaluated, starting with $i=0$).
  106. This results in a mathematical expression:
  107. Let I($x_i, y_i$) an Image with grayscale values and $g_n$ the grayscale value of the pixel $(x_i, y_i)$.
  108. Also let $s(g_i - g_c)$ with $g_c$ = grayscale value of the center pixel.
  109. $$
  110. s(v, g_c) = \left\{
  111. \begin{array}{l l}
  112. 1 & \quad \text{if v $\geq$ $g_c$}\\
  113. 0 & \quad \text{if v $<$ $g_c$}\\
  114. \end{array} \right.
  115. $$
  116. $$LBP_{n, g_c = (x_c, y_c)} = \sum\limits_{i=0}^{n-1} s(g_i, g_c)^{2i} $$
  117. The outcome of this operations will be a binary pattern.
  118. \item Given this pattern, the next step is to divide the pattern in cells. The
  119. amount of cells depends on the quality of the result, so trial and error is in order.
  120. Starting with dividing the pattern in to 16 cells.
  121. \item Compute a histogram for each cell.
  122. \pagebreak
  123. \begin{figure}[h!]
  124. \center
  125. \includegraphics[scale=0.7]{cells.png}
  126. \caption{Divide in cells(Pietik\"ainen et all (2011))}
  127. \end{figure}
  128. \item Consider every histogram as a vector element and concatenate these. The result is a
  129. feature vector of the image.
  130. \item Feed these vectors to a support vector machine. This will ''learn'' which vector
  131. are.
  132. \end{itemize}
  133. To our knowledge, LBP has yet not been used in this manner before. Therefore,
  134. it will be the first thing to implement, to see if it lives up to the
  135. expectations. When the proof of concept is there, it can be used in the final
  136. program.
  137. Important to note is that due to the normalization of characters before
  138. applying LBP. Therefore, no further normalization is needed on the histograms.
  139. Given the LBP of a character, a Support Vector Machine can be used to classify
  140. the character to a character in a learning set. The SVM uses
  141. \subsection{Matching the database}
  142. Given the LBP of a character, a Support Vector Machine can be used to classify
  143. the character to a character in a learning set. The SVM uses the collection of
  144. histograms of an image as a feature vector. The SVM can be trained with a
  145. subsection of the given dataset called the ''Learning set''. Once trained, the
  146. entire classifier can be saved as a Pickle object\footnote{See
  147. \url{http://docs.python.org/library/pickle.html}} for later usage.
  148. \section{Implementation}
  149. In this section we will describe our implementations in more detail, explaining
  150. choices we made.
  151. \subsection{Licenseplate retrieval}
  152. In order to retrieve the license plate from the entire image, we need to
  153. perform a perspective transformation. However, to do this, we need to know the
  154. coordinates of the four corners of the licenseplate. For our dataset, this is
  155. stored in XML files. So, the first step is to read these XML files.\\
  156. \\
  157. \paragraph*{XML reader}
  158. \paragraph*{Perspective transformation}
  159. Once we retrieved the cornerpoints of the license plate, we feed those to a
  160. module that extracts the (warped) license plate from the original image, and
  161. creates a new image where the license plate is cut out, and is transformed to a
  162. rectangle.
  163. \subsection{Noise reduction}
  164. The image contains a lot of noise, both from camera errors due to dark noise
  165. etc., as from dirt on the license plate. In this case, noise therefore means
  166. any unwanted difference in color from the surrounding pixels.
  167. \paragraph*{Camera noise and small amounts of dirt}
  168. The dirt on the license plate can be of different sizes. We can reduce the
  169. smaller amounts of dirt in the same way as we reduce normal noise, by applying
  170. a Gaussian blur to the image. This is the next step in our program.\\
  171. \\
  172. The Gaussian filter we use comes from the \texttt{scipy.ndimage} module. We use
  173. this function instead of our own function, because the standard functions are
  174. most likely more optimized then our own implementation, and speed is an
  175. important factor in this application.
  176. \paragraph*{Larger amounts of dirt}
  177. Larger amounts of dirt are not going to be resolved by using a Gaussian filter.
  178. We rely on one of the characteristics of the Local Binary Pattern, only looking
  179. at the difference between two pixels, to take care of these problems.\\
  180. Because there will probably always be a difference between the characters and
  181. the dirt, and the fact that the characters are very black, the shape of the
  182. characters will still be conserved in the LBP, even if there is dirt
  183. surrounding the character.
  184. \subsection{Character retrieval}
  185. The retrieval of the character is done the same as the retrieval of the license
  186. plate, by using a perspective transformation. The location of the characters on
  187. the license plate is also available in de XML file, so this is parsed from that
  188. as well.
  189. \subsection{Creating Local Binary Patterns and feature vector}
  190. \subsection{Classification}
  191. \section{Finding parameters}
  192. Now that we have a functioning system, we need to tune it to work properly for
  193. license plates. This means we need to find the parameters. Throughout the
  194. program we have a number of parameters for which no standard choice is
  195. available. These parameters are:\\
  196. \\
  197. \begin{tabular}{l|l}
  198. Parameter & Description\\
  199. \hline
  200. $\sigma$ & The size of the Gaussian blur.\\
  201. \emph{cell size} & The size of a cell for which a histogram of LBPs will
  202. be generated.\\
  203. $\gamma$ & Parameter for the Radial kernel used in the SVM.\\
  204. $c$ & The soft margin of the SVM. Allows how much training
  205. errors are accepted.
  206. \end{tabular}\\
  207. \\
  208. For each of these parameters, we will describe how we searched for a good
  209. value, and what value we decided on.
  210. \subsection{Parameter $\sigma$}
  211. The first parameter to decide on, is the $\sigma$ used in the Gaussian blur. To
  212. find this parameter, we tested a few values, by checking visually what value
  213. removed most noise out of the image, while keeping the edges sharp enough to
  214. work with. By checking in the neighbourhood of the value that performed best,
  215. we where able to 'zoom in' on what we thought was the best value. It turned out
  216. that this was $\sigma = ?$.
  217. \subsection{Parameter \emph{cell size}}
  218. The cell size of the Local Binary Patterns determines over what region a
  219. histogram is made. The trade-off here is that a bigger cell size makes the
  220. classification less affected by relative movement of a character compared to
  221. those in the learning set, since the important structure will be more likely to
  222. remain in the same cell. However, if the cell size is too big, there will not
  223. be enough cells to properly describe the different areas of the character, and
  224. the feature vectors will not have enough elements.\\
  225. \\
  226. In order to find this parameter, we used a trial-and-error technique on a few
  227. basic cell sizes, being ?, 16, ?. We found that the best result was reached by
  228. using ??.
  229. \subsection{Parameters $\gamma$ \& $c$}
  230. The parameters $\gamma$ and $c$ are used for the SVM. $c$ is a standard
  231. parameter for each type of SVM, called the 'soft margin'. This indicates how
  232. exact each element in the learning set should be taken. A large soft margin
  233. means that an element in the learning set that accidentally has a completely
  234. different feature vector than expected, due to noise for example, is not taken
  235. into account. If the soft margin is very small, then almost all vectors will be
  236. taken into account, unless they differ extreme amounts.\\
  237. $\gamma$ is a variable that determines the size of the radial kernel, and as
  238. such blablabla.\\
  239. \\
  240. Since these parameters both influence the SVM, we need to find the best
  241. combination of values. To do this, we perform a so-called grid-search. A
  242. grid-search takes exponentially growing sequences for each parameter, and
  243. checks for each combination of values what the score is. The combination with
  244. the highest score is then used as our parameters, and the entire SVM will be
  245. trained using those parameters.\\
  246. \\
  247. We found that the best values for these parameters are $c=?$ and $\gamma =?$.
  248. \section{Results}
  249. The goal was to find out two things with this research: The speed of the
  250. classification and the accuracy. In this section we will show our findings.
  251. \subsection{Speed}
  252. Recognizing license plates is something that has to be done fast, since there
  253. can be a lot of cars passing a camera in a short time, especially on a highway.
  254. Therefore, we measured how well our program performed in terms of speed. We
  255. measure the time used to classify a license plate, not the training of the
  256. dataset, since that can be done offline, and speed is not a primary necessity
  257. there.\\
  258. \\
  259. The speed of a classification turned out to be blablabla.
  260. \subsection{Accuracy}
  261. Of course, it is vital that the recognition of a license plate is correct,
  262. almost correct is not good enough here. Therefore, we have to get the highest
  263. accuracy score we possibly can.\\
  264. \\ According to Wikipedia
  265. \footnote{
  266. \url{http://en.wikipedia.org/wiki/Automatic_number_plate_recognition}},
  267. commercial license plate recognition software score about $90\%$ to $94\%$,
  268. under optimal conditions and with modern equipment. Our program scores an
  269. average of blablabla.
  270. \section{Conclusion}
  271. \end{document}