Using Tesseract to Recognize License Plates

Why does Tesseract not recognize the text on the licence plate while easyocr does?

I'm kind of curious why did you use bilateralFilter, Canny, findContours etc.? Did you see the result of each method?

Anyway, if you set the page-segmentation-mode to 6 which is:

Assume a single uniform block of text.

The result will be:

34 DUA34

Code:

import cv2
import pytesseract

# Load the image
img = cv2.imread("vHQ5q.jpg")

# Convert to the gray-scale
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# OCR
print(pytesseract.image_to_string(gry, config="--psm 6"))

# Display
cv2.imshow("", gry)
cv2.waitKey(0)

You should know the Page segmentation method.

I've got the result using pytesseract-version-0.3.7.

character recognition from license plate with opencv python

Use easyocr. It uses Deep Learning models:

# install using python -m pip install easyocr

import easyocr

# create reader
reader = easyocr.Reader(['en'])

# read characters
img = "https://i.stack.imgur.com/2Kzu8.png"

characters = reader.readtext(img, detail=0)
print(characters)
# ['ZG', '8524AF']

See documentation for more details, parameters and languages

Update & Results from Colab

To avoid capturing of none plate numbers character use allowlist parameter

#Narrowing characters 
import string

ALLOWED_LIST = string.ascii_uppercase+string.digits
characters = reader.readtext(img, detail=0, allowlist=ALLOWED_LIST )
print(characters)
# ['ZG', '8524AF']

My results from Google Colab

Sample Image

How to tune tesseract for identifying number plate of a car more accurately?

You are using tesseract as a general model for your problem you can tune your model for that you need to generate synthetic data for your number plates with this

https://github.com/Belval/TextRecognitionDataGenerator

and then you can tune your model using the steps provided

https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00---Finetune

https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00

I've tuned the tesseract on synthetic data and it works like a charm, tried CNN models and tesseract both and tesseract trains better with lesser data and gives better performance.



Related Topics



Leave a reply



Submit