report.tex 19 KB

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