Automatic Car Number Plate Detection

Shristi Agarwal
3 min readSep 7, 2021

Hi All

So here, i am gonna share a Machine Learning model for the Automatic Car Number Plate detection.

Various steps are required to build this detection modelThe two major libraries I have used is Opencv and the easyocr.

So lets start — —

Used Packages : Jupyter Notebook , Python3, Major Libraries need to to install using pip command(opencv, matplotlib , numpy , easyocr ,imutils), also downloaded some car number plate images.

So, firstly we will convert our RGB image to the gray scale image to reduce the parameters of the image using cv2.COLOR_BGR2GRAY.

Now we will do the filtering on the image to reduce the noise in the image, and we will do the edge detection, which helps us to different between the certain shapes present in the image like rectangle(for car no. plate).

I used cv2.bilateralFilter() function for filtration of the image and cv2.Canny() function for the edge detection.

Now we will do the contour detection, what does it means that we will now actually find the shapes i.e. the polygons present in the image, here contour means where some points meet up to form certain shape, which may likely detect the shape of the number plate, and this can be done using the cv2.findContours() function which has arguments like cv2.RETR_TREE and cv2.CHAIN_APPROX_SIMPLE which defines the return value and what type of shape we roughly want to be contoured, like here we want the line, connecting four dots.

Now we will check that is those four detected dots through contouring are actually representing number plate or not using the cv2.approxPolyDP() function which specifies that how correctly we get our desired shape.

So, to make it more clear we will applying masking to it and then isolate the desired section, and for masking I used the numpy library which masks the number plate in the same size as of the initial image , and here I used cv2.bitwise() for the segmentation of the number plate.

After that I just extracted the the above number plate from the image, because helps a lot as many parameters will reduce at once, which will good for further processing, so cropped the upper image using simple list slicing method.

Now, I have just applied the easyocr to just read the characters from the cropped image, created a easyocr.Reader() object and applied the reader.readtext() function on it by passing cropped image as the argument.

Now just simply put the detected number of the car to the original image using cv2.putText() function and draw a rectangle around the number plate of the car on the image.

Here, I created a dummy web portal where information of the license holder will be shown, if we put the detected car number.

Thanks for the read….

Happy Learning🙃…

--

--