License plate recognition based on HyperLPR

2021SC@SDUSC

Source code download address: HyperLPR: HyperLRP is an open source, high-performance Chinese license plate recognition library based on deep learning. It is developed by Beijing Zhiyun View Technology Co., Ltd. and supports PHP, C/C + +, Python language and Windows/Mac/Linux/Android/IOS platform.

See the first analysis for details of source code configuration

This time, part of the following code is analyzed:

 val = segmentation.slidingWindowsEval(image_gray)

This line of code is the 217 line method of pipline.py:

def slidingWindowsEval(image):
    windows_size = 16;
    stride = 1
    height= image.shape[0]
    t0 = time.time()
    data_sets = []

    for i in range(0,image.shape[1]-windows_size+1,stride):
        data = image[0:height,i:i+windows_size]
        data = cv2.resize(data,(23,23))
        # cv2.imshow("image",data)
        data = cv2.equalizeHist(data)
        data = data.astype(np.float)/255
        data=  np.expand_dims(data,3)
        data_sets.append(data)

    res = model2.predict(np.array(data_sets))
    print("division",time.time() - t0)

    pin = res
    p = 1 -  (res.T)[1]
    p = f.gaussian_filter1d(np.array(p,dtype=np.float),3)
    lmin = l.argrelmax(np.array(p),order = 3)[0]
    interval = []
    for i in range(len(lmin)-1):
        interval.append(lmin[i+1]-lmin[i])

    if(len(interval)>3):
        mid  = get_median(interval)
    else:
        return []
    pin = np.array(pin)
    res =  searchOptimalCuttingPoint(image,pin,0,mid,3)

    cutting_pts = res[1]
    last =  cutting_pts[-1] + mid
    if last < image.shape[1]:
        cutting_pts.append(last)
    else:
        cutting_pts.append(image.shape[1]-1)
    name = ""
    confidence =0.00
    seg_block = []
    for x in range(1,len(cutting_pts)):
        if x != len(cutting_pts)-1 and x!=1:
            section = image[0:36,cutting_pts[x-1]-2:cutting_pts[x]+2]
        elif  x==1:
            c_head = cutting_pts[x - 1]- 2
            if c_head<0:
                c_head=0
            c_tail = cutting_pts[x] + 2
            section = image[0:36, c_head:c_tail]
        elif x==len(cutting_pts)-1:
            end = cutting_pts[x]
            diff = image.shape[1]-end
            c_head = cutting_pts[x - 1]
            c_tail = cutting_pts[x]
            if diff<7 :
                section = image[0:36, c_head-5:c_tail+5]
            else:
                diff-=1
                section = image[0:36, c_head - diff:c_tail + diff]
        elif  x==2:
            section = image[0:36, cutting_pts[x - 1] - 3:cutting_pts[x-1]+ mid]
        else:
            section = image[0:36,cutting_pts[x-1]:cutting_pts[x]]
        seg_block.append(section)
    refined = refineCrop(seg_block,mid-1)

    t0 = time.time()
    for i,one in enumerate(refined):
        res_pre = cRP.SimplePredict(one, i )
        # cv2.imshow(str(i),one)
        # cv2.waitKey(0)
        confidence+=res_pre[0]
        name+= res_pre[1]
    print("character recognition ",time.time() - t0)

    return refined,name,confidence

The above code uses the template matching method for analysis.

The template matching method designs a fixed template and an evaluation function to measure the matching degree of the template according to the standard style of the license plate and the structure, size and spacing characteristics of the characters. Then, the template slides from left to right in the normalized image, and the corresponding evaluation value is calculated each time, Finally, the template sliding position with the highest matching degree is selected as the position of character segmentation. The disadvantage of template matching method is that it has high requirements for license plate image. When the inclination angle of license plate is very small, the frame is removed cleanly, the image noise is less, and the character size and character spacing are standard, the algorithm has fast speed and good segmentation effect; When the quality of license plate image is general, the segmentation effect of this algorithm is often unsatisfactory.
HyperLPR adopts the template matching method, and the general idea is as follows:
1. Conduct a Guassian Filter on the license plate
2. Set the template width for template matching
3. Template matching
 

The confidence level of recognition one and sliding windows Eval is different. When the confidence level is low, there may be different license plate recognition results between the two methods.

Tags: Python

Posted on Mon, 29 Nov 2021 07:08:05 -0500 by garethj