Object Recognition using CNN

M G GOVARDHAN GOWDA
4 min readSep 7, 2021
Car number plate detection

Task 8

👉Create a model that will detect a car in a live stream or video and recognize characters on the number plate of the car.

👉Secondly, it will use the characters and fetch the owners' information using RTO APIs.

👉Create a Web portal where all this information will be displayed (using HTML, CSS and js)

📌 Note: You may create your own detection model.

Now lets us start with the Coding Part. Here we have imported some library then trained our model to detect number plate of our car

Now import the image from your local device and convert the image of the car captured in Black and White.

Now we’ll need to apply some pre-processing in OpenCV to make contour detection work. Namely, we convert the image to grayscale, apply a bilateral filter with cv2.bilateralFilter. After that, using OpenCV’s bilateral filter function, we reduce the noise in the image for better edge detection.

cv2.drawContours() function takes five arguments-

  1. The first argument is the image in which the detected contours will be drawn.
  2. The second argument is the variable that stores all the detected contours.
  3. Then, the third argument is contour indexes. Here we use the value -1 which will use the indexes of all the contours detected in our image. Hence all of the contours will be drawn on the image.
  4. After that, the fourth argument is the color in which contours will be drawn.
  5. The fifth argument is the thickness of the contour curve to be drawn.

A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV

if you have the contours detected, you can crop the contours by adding the following lines to your code, just after contours, hierarchy = cv2.findContours(threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE):

You can extract text from images with EasyOCR, a deep learning-based OCR tool in Python. EasyOCR performs very well on invoices, handwriting, car plates, and public signs as shown above.

Now in OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.putText() the method is used to draw a text string on any image.

Syntax: cv2.putText(image, text, org, font, font scale, color[, thickness[, lineType[, bottomLeftOrigin]]])

Parameters:
image: It is the image on which text is to be drawn.
text: Text string to be drawn.
org: It is the coordinates of the bottom-left corner of the text string in the image. The coordinates are represented as tuples of two values i.e. (X coordinate value, Y coordinate value).
font: It denotes the font type of the text. Some of the font types are as following: FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN, etc.
font scale: Font scale factor that is font-specific base size.
color: It is the color of the text you want. For BGR(Blue, Green, Red), we pass a tuple. eg: (255, 0, 0) for blue color.
thickness: It is the thickness of the line in px(Pixels).
lineType: This is an optional parameter. It gives the type of line to be used.
bottom-left origin: This is an optional parameter. When it is true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

Return Value: It returns an image.

output

--

--

M G GOVARDHAN GOWDA

MLOPS internship trainee @LinuxWorld informatics Pvt. LTD. || Student @Dayananda Sagar University |