License Plate Recognition

License Plate Recognition

License Plate Recognition:-

License Plate Recognition (LPR) is an image-processing technology used to identify vehicles by their license plates. This technology is used in various security and traffic applications, such as the access-control system featured in the following animation:

Open ALPR:-

  • The OpenALPR CarCheck API is a hosted ALPR web service for application integration. Send images to the OpenALPR cloud servers and the response will be a JSON document describing the license plates, and vehicle variables such as color, make, and body type.
  • There are a number of plans that offer a fixed number of recognitions per month. Select a plan below.

 

License Plate Recognition

License Plate img

Source Code:-

ALPR FROM IMAGE:-

import json
import base64
import requests
from authKey import SECRET_KEY

IMAGE_PATH = 'first.jpg'

with open(IMAGE_PATH, 'rb') as image_file:
img_base64 = base64.b64encode(image_file.read())

url = 'https://api.openalpr.com/v2/recognize_bytes?recognize_vehicle=1&country=us&secret_key=%s' % (SECRET_KEY)
r = requests.post(url, data = img_base64)

num_plate=(json.dumps(r.json(), indent=2))
info=(list(num_plate.split("candidates")))
print(info)
plate=info[1]
plate=plate.split(',')[0:3]
p=plate[1]
p1= p.split(":")
number=p1[1]
number=number.replace('"','')
number=number.lstrip()
print (number)

if number == "MH120E4433":

print("----------------------------")
print("Owner Name: Champ")
print("Vehicle Nmuber: %s"%number)
print("Address: MAHARASHTRA")

ALPR USING CAMERA:-

import cv2
import time
import json
import base64
import requests
from authKey import SECRET_KEY

cam = cv2.VideoCapture(1)
while True:

 

_,img = cam.read()
key = cv2.waitKey(1) & 0xff
cv2.imshow("LicensePlate",img)
if ( key == ord('q')):

cv2.destroyAllWindows()
print("Captured...")
cv2.imwrite("first.jpg",img)
time.sleep(5)
IMAGE_PATH = 'first.jpg'

with open(IMAGE_PATH, 'rb') as image_file:

img_base64 = base64.b64encode(image_file.read())

url = 'https://api.openalpr.com/v2/recognize_bytes?recognize_vehicle=1&country=us&secret_key=%s' % (SECRET_KEY)
r = requests.post(url, data = img_base64)

num_plate=(json.dumps(r.json(), indent=2))
info=(list(num_plate.split("candidates")))
print(info)
plate=info[1]
plate=plate.split(',')[0:3]
p=plate[1]
p1= p.split(":")
number=p1[1]
number=number.replace('"','')
number=number.lstrip()
print (number)

if number == "MH120E4433":

print("----------------------------")
print("Owner Name: Champ")
print("Vehicle Nmuber: %s"%number)
print("Address: MAHARASHTRA")

elif key == 27:

break

cam.release()
cv2.destroyAllWindows()

 

Summary

In this tutorial, you learned how to build a basic Automatic License/Number Plate Recognition system using OpenCV and Python.

Our ANPR method relied on basic computer vision and image processing techniques to localize a license plate in an image, including morphological operations, image gradients, thresholding, bitwise operations, and contours.

This method will work well in controlled, predictable environments — like when lighting conditions are uniform across input images and license plates are standardized (such as dark characters on a light license plate background).

However, if you are developing an ANPR system that does not have a controlled environment, you’ll need to start inserting machine learning and/or deep learning to replace parts of our plate localization pipeline.

HOG

+ Linear SVM is a good starting point for plate localization if your input license plates have a viewing angle that doesn’t change more than a few degrees. If you’re working in an unconstrained environment with viewing angles that can vary dramatically, then deep learning-based models such as Faster R-CNN, SSDs, and YOLO will likely obtain better accuracy.

Additionally, you may need to train your own custom license plate character OCR model. We were able to get away with Tesseract in this blog post, but a dedicated character segmentation and OCR model (like the ones I cover in the PyImageSearch Gurus course) may be required to improve your accuracy.

I hope you enjoyed this tutorial!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.