License Plate Detection & License Plate Recognition using OpenCV

We Create a Python program for Vehicle Number plate Detection and Recognition to Identify Owner of Vehicle


we use numpy

cv2 library


Step 1:

Download and Install Tesseract-OCR software from

Download pytesseract python package:- pip install pytesseract

Step 2:

Import packages in your python code

Now set your tesseract.exe path where you extract it

pytesseract.pytesseract.tesseract_cmd = r’C:\Program Files\Tesseract-OCR\tesseract.exe’

Now load vehicle image using imread function of cv2 library: img = cv2.imread(“car_1.jpg”)

resize this image: img = cv2.resize(img, (600,400))

show this image

cv2.imshow(“car”, img)

We need only important features of this image, So convert this image to grayscale for reducing image features: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Step 3: Now, Apply some Filters and detect the edges :

filter = cv2.bilateralFilter(gray, 13,15,15)
edge = cv2.Canny(filter, 170,200)

edges detection

step 3: Finding Contours

Contour detection doesn’t have to be hard. A Licence plate of a vehicle is assumed to be a rectangle. And a rectangle has four edges. And it’s also safe to assume that the Licence plate of a vehicle has four edges.

License Plate Detected
License Plate

License plate detection code is:

for c in ctn:
peri=cv2.arcLength(c, True)
if len(apporx)==4:
x,y,w,h = cv2.boundingRect(apporx)
cimg = img[y:y+h, x:x+w]
cv2.imshow(“plate”, cimg)
text=pytesseract.image_to_string(cimg, lang=”eng”)
final = cv2.drawContours(img,[apporx],-1,(255,0,0),3)

cv2.imshow(“plate detected”, img)

License plate Number Recognition

Note: — If you got a License Number so you can put this number RTO API and get the details of the Vehicle owner

Github link of this Project is: