


What are we going to do: Now, we would like to find the contour that is rectangular in shape, and we would be using the function cv2.approxPolyDP( current contour, maximum distance from contour to approximated contour, True) for this, which will approximate a polygon (in our case, a rectangle). contours=sorted(contours, key = cv2.contourArea, reverse = True) Number_Plate_Contour = 0 So we would loop over all the contours, and find out which contour is fit to be a license plate. Why this? : The above code would give us all the contours, which would include very small and insignificant ones as well so we would want to get rid of those and would want only the major contours. Here, we would declare an empty variable that would later refer to the contour corresponding to the number plate. What are we going to do: Now we would sort the contours according to their area, and then take the top 30 contours. Why this?: We make a copy of the original image so that we don’t tamper the original image. First, we would make a copy of the original image and then display the contours on it. What are we going to do: Now after finding the contours, we would want to display them on the actual image. contours, heirarchy = cv2.findContours(py(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) Why this?: Contours are basically the curves that join all the continuous points having the same intensity or color, cv2.findContours( image name, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) join all the points along the boundary of an object, therefore using the image with edges detected is better. We will be using cv2.findContours( image name, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) to do so. What are we going to do: Now after detecting the edges of objects in the image, we would like to find the major contours in the processed image. image = cv2.imread(filename) image = imutils.resize(image, width=500) cv2.imshow("Original Image", image) cv2.waitKey(0) Why this?: Resizing an image is a good practice, it helps with processing the image better and also helps the machine train on smaller images faster (We aren’t dealing with this aspect though, in this tutorial). What are we going to do: Now we would use the function cv2.imread( path_to_file ) in order to read the image and imutils.resize( image, width = size you want ) would resize the image. Here ‘filename’ stores the address of the file we would select. Tk().withdraw() filename = askopenfilename() Why this?: This would help us in letting the user choose the image, which would later be used for license plate detection. What are we going to do: After importing all the necessary modules we would want to accept an image by the user. import numpy as np import cv2 import imutils from tkinter import Tk from tkinter.filedialog import askopenfilename Firstly, we would be importing all the modules needed for the program.
