0

I have a problem with Russian plates. When I want to classifychars with openalpr tool I get something below:

before

after

OCR cutted my upper fragment of numbers. I generate new .conf file for this country with this parameters:

char_analysis_min_pct = 0.29
char_analysis_height_range = 0.20
char_analysis_height_step_size = 0.10
char_analysis_height_num_steps = 6

segmentation_min_speckle_height_percent = 0.3
segmentation_min_box_width_px = 6
segmentation_min_charheight_percent = 0.1;
segmentation_max_segment_width_percent_vs_average = 1.95;

plate_width_mm= 520
plate_height_mm = 112

multiline = 1

char_height_mm = 58
char_width_mm = 44

char_whitespace_top_mm = 18
char_whitespace_bot_mm = 18

template_max_width_px = 300
template_max_height_px = 64

; Higher sensitivity means less lines
plateline_sensitivity_vertical = 10
plateline_sensitivity_horizontal = 45

; Regions smaller than this will be disqualified
min_plate_size_width_px = 65
min_plate_size_height_px = 18

; Results with fewer or more characters will be discarded
postprocess_min_characters = 8
postprocess_max_characters = 9

;detector_file= eu.xml
ocr_language = lamh

;Override for postprocess letters/numbers regex.
postprocess_regex_letters = [A,B,C,E,H,K,M,O,P,T,X,Y]
postprocess_regex_numbers = [0-9]

; Whether the plate is always dark letters on light background, light letters on dark background, or both
; value can be either always, never, or auto
invert = auto

Anyone have a idea how to solve it?

Starting I used OCR file from this repository https://github.com/KostyaKulakov/Russian_System_of_ANPR

Orginal photo

Thank you.

Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
MarCovy
  • 17
  • 9
  • You should first extract the area and after do OCR – lucians May 15 '18 at 09:32
  • Also, can you post original image ? – lucians May 15 '18 at 09:38
  • @Link I used the tool from repository OpenALPR openalpr-utils-classifychars, so this tool extract the area becfore OCR is runed. I added in my post link to orginal photo. – MarCovy May 15 '18 at 10:33
  • OpenALPR is a must ? Once you have an image like the one provided above, recognizing chars it's not difficult because it's all clean. The problem come when you have to extract the license plate from a whole car image/video. So, all the images you have are like the one posted above ? I am saying that with the goal to approach the problem in another way and also because I never used that kind of utility. It's all automatic while the "solution" I could provide it's more manually.. – lucians May 15 '18 at 10:43
  • @Link I need open ALPR because I build for my use system to licence plate detection. I must add Russian plate standard to OpenALPR engine because sometimes I have guest from Russia. So, I need to extract tiles with letters and numbers to train OCR. Everything is good when I used European standard plates. When I used Russia I have situation which I described above. – MarCovy May 15 '18 at 10:49
  • @Link can you tell my your "solution" ? – MarCovy May 15 '18 at 10:55

1 Answers1

2

Maybe something like this ?

res

import cv2
import numpy as np

image = cv2.imread('plate.png')
# cv2.imshow('original', image)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# cv2.imshow('gray', gray)

ret, thresh = cv2.threshold(gray, 60, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('thresh', thresh)

blur = cv2.medianBlur(thresh, 1)

kernel = np.ones((10, 20), np.uint8)
img_dilation = cv2.dilate(blur, kernel, iterations=1)
cv2.imshow('dilated', img_dilation)

im2, ctrs, hier = cv2.findContours(img_dilation.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# sort contours
sorted_ctrs = sorted(ctrs, key=lambda ctr: cv2.boundingRect(ctr)[0])

for i, ctr in enumerate(sorted_ctrs):
    # Get bounding box
    x, y, w, h = cv2.boundingRect(ctr)

    # Getting ROI
    roi = image[y:y + h, x:x + w]

    if (h > 50 and w > 50) and h < 200:

        # show ROI
        # cv2.imshow('segment no:'+str(i),roi)
        cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 255), 1)
        # cv2.waitKey(0)

        cv2.imwrite('{}.png'.format(i), roi)

cv2.imshow('marked areas', image)
cv2.waitKey(0)

This will save you all the ROI you need...

out2

(the last image can be segmented again)

... and do OCR on each character. In my opinion this could be easier than doing OCR on whole image.

If you do some thresholding on each image and add a, IDK, 5 pixel border then all the process would be easier.

lucians
  • 2,239
  • 5
  • 36
  • 64