Number Plate Classification using Open-CV

Plaban Nayak
3 min readOct 18, 2020

The objective of this tutorial is to use open cv Haar feature-based classifiers to detect the number plates from the images. This will be a very simple machine learning approach to object detection in OpenCV. To learn how Haar cascade object detection works before you begin this notebook, check out this site: https://docs.opencv.org/3.4/db/d28/tutorial_cascade_classifier.html.

Import Required Libraries

Set Default Parameters

Create a trained classifier object with the xml file

nPlateCascade = cv2.CascadeClassifier(r"…..\Number_Plates\haarcascade_russian_plate_number.xml")

This pretrained classifier xml file is downloaded from https://github.com/opencv/opencv/tree/master/data/haarcascades. There are many pretrained classifier xml files included on this site for detecting objects of a particular type, e.g. faces (frontal, profile), pedestrians etc. Here have chosen the one that works best for detecting number/license plates:

Steps Involved in read the input images and extracting the number / license plates

  1. Loop through the images in the folder.
  2. Use cv2.VideoCapture() to read image in the directory.
  3. Convert the image to gray scale. Object detection works best on grayscale images
  4. Create an OpenCV trained classifier object using the pretrained classifier xml file referenced above.
  5. Apply OpenCV’s detectMultiScale() function to detect the number /license plates.
  6. Once the detection is done, the result is a list of bounding boxes (x, y, w, h) representing the location of each plate the classifier found.
  7. The number plates detected are saved into another folder

Code Illustration

Output:

Scanned Number Plates saved into a Folder

References:

Connect

--

--