Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to improve accuracy/prediction for EasyOCR?

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])
like image 307
k_p Avatar asked Oct 15 '25 15:10

k_p


1 Answers

  • 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])
like image 130
Bilal Avatar answered Oct 19 '25 00:10

Bilal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!