Number Plate Classification using Open-CV
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
- Loop through the images in the folder.
- Use cv2.VideoCapture() to read image in the directory.
- Convert the image to gray scale. Object detection works best on grayscale images
- Create an OpenCV trained classifier object using the pretrained classifier xml file referenced above.
- Apply OpenCV’s detectMultiScale() function to detect the number /license plates.
- 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.
- The number plates detected are saved into another folder