2

I am trying to get characters from vehicle number plate. But getting few wrong predictions like

enter image description here

I am getting output as UP74 BD 3465, which is wrong . There are many examples where B is predicted as 8 and many more.

  • How to improve it's accuracy?.
  • How to preprocess the image to get right prediction or any other approach?
import matplotlib.pyplot as plt
import easyocr
from pylab import rcParams
from IPython.display import Image

rcParams['figure.figsize'] = 8, 16
reader = easyocr.Reader(['en'])

output = reader.readtext(path)
for i in range(len(output)):
    print(output[i][-2])
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
k_p
  • 283
  • 6
  • 17
  • see about training the OCR for that font. it seems to "see" the glyphs well enough, even though the picture has very poor contrast. – Christoph Rackwitz Jul 06 '21 at 07:04
  • @ChristophRackwitz hi , i have gone through yr process but still not getting proper results ..i have the data for number plate as https://drive.google.com/drive/folders/1_XHCfT3_zHOS8hO_fTG5OWt80ZkGxGn8?usp=sharing can you suggest some approach so that it gives high accuracy on any such image in the link provided – k_p Jul 06 '21 at 10:33

3 Answers3

5
  • Firstly, I suggest you to read this topic about image-enhancement for OCR: LINK.

  • Secondly, In the same sense of the topic above you can solve it for this particular image using Thresholding, Gaussian Filtering, and Histogram Equalization after you crop the region of interest (ROI), so the output image will look like:

enter image description here

and the output will be:

UP14 BD 3465

import cv2
import easyocr
from pylab import rcParams
# import numpy library
import numpy as np

# define the path
path = 'input.png'

# read the image
img = cv2.imread(path, 0)

# find the white rectangle
th = img.copy()
th[th<200] = 0

bbox = np.where(th>0)
y0 = bbox[0].min()
y1 = bbox[0].max()
x0 = bbox[1].min()
x1 = bbox[1].max()

# crop the region of interest (ROI)
img = img[y0:y1, x0:x1]

# histogram equalization
equ = cv2.equalizeHist(img)
# Gaussian blur
blur = cv2.GaussianBlur(equ, (5, 5), 1)

# manual thresholding
th2 = 60 # this threshold might vary!
equ[equ>=th2] = 255
equ[equ<th2]  = 0

# Now apply the OCR on the processed image
rcParams['figure.figsize'] = 8, 16
reader = easyocr.Reader(['en'])

output = reader.readtext(equ)

for i in range(len(output)):
    print(output[i][-2])
Bilal
  • 3,191
  • 4
  • 21
  • 49
  • 1
    hi , i have gone through yr process but still not getting proper results ..i have the data for number plate as https://drive.google.com/drive/folders/1_XHCfT3_zHOS8hO_fTG5OWt80ZkGxGn8?usp=sharing can you suggest some approach so that it gives high accuracy on any such image in the link provided. I am stucked at this point thanks – k_p Jul 06 '21 at 10:32
  • @k_p "*still not getting proper results*" for this image or the rest of the dataset you mean? because I have tested this code with the given image only! – Bilal Jul 06 '21 at 10:52
  • Hi , i want any general code so that it should work on any number plate(provided in link) which should work in our use case of Automatic number plate recognition, doing image processing for each image will be difficult ...can you help me out in writing a general code which should work on maxm of image in the link , i have tried a lot but not getting proper code Thanks in advance – k_p Jul 06 '21 at 11:08
  • @k_p I'm not sure that there is a general solution without using deep learning. – Bilal Jul 06 '21 at 14:50
  • I have tried deep learning ..build a CNN model for recognition of characters...but not getting a robust method to seperate each character so that I apply character recognition method. any idea ? – k_p Jul 08 '21 at 22:06
  • @k_p "*any idea?*" you may try [easy-ocr](https://github.com/JaidedAI/EasyOCR) – Bilal Mar 04 '22 at 19:50
0

The image that you have given is too dark, so if you want you can follow this link https://stackoverflow.com/a/50053219/17233488. Also after increasing the brightness, you might see some shadow on the image, so for this, you can go through this link, https://stackoverflow.com/a/44752405/17233488. Also for the other tasks, try using deskew and other morphological processes as suggested above.

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30586619) – Flair Dec 14 '21 at 20:25
0

There is another method to recognize it correctly.

firstly,

pip3 install paddleocr

Then

paddleocr  --image_dir=./J8uyr.png

U can get the results below.

[[[20.0, 10.0], [202.0, 10.0], [202.0, 42.0], [20.0, 42.0]], ('UP14BD3465', 0.9637424349784851)]

I recommend to use paddleOCR (https://github.com/PaddlePaddle/PaddleOCR)

vimuth
  • 5,064
  • 33
  • 79
  • 116
刘威威
  • 21
  • 2