21 night license plate recognition (matlab program)

1. Brief description

      

Briefly talk about the implementation idea:

Read the picture, convert it to grayscale, calculate the grayscale histogram , and estimate the threshold (threshold calculation here is very important. After the threshold algorithm, select the most appropriate threshold), and then binarize. Just display the image.

  1. Goals

Input a picture of license plate to realize the three steps of license plate location, character cutting and character recognition. At the same time, it can be made into out-of-warehouse recognition, voice broadcast, and out-of-warehouse functions according to needs.

  1. Design steps:

The designed process of license plate recognition includes image preprocessing, license plate segmentation, character segmentation, and character recognition. See the matalb program for details.

 

  1. Program explanation

1) The first part is image preprocessing.

This part borrows from other people's programs to detect the edge of the grayscale image with the sobel operator; then corrode the edge image to remove the thin and intermittent edges; close the remaining area to fill the image, and you can see it at this time A large connected domain is formed in the license plate area; the bwareaopen function is called to remove the small connected domain. At this time, only the license plate area of ​​b is 1 in the entire binary image. As shown below:

 

fb7cdc56f13d663cf102ed5e42fbd3ae.png

 

 

  1. The second part is the extraction of the license plate

The work of this part is to take out the white area in the previous step, which corresponds to the license plate area. The design idea is as follows: First, put the coordinates of all points of 1 in the binary image f into the array location_of_1, traverse and calculate these coordinates, and find the point a with the largest sum of the x coordinate and the y coordinate and the smallest point b, a is is the upper left corner of the license plate, b is the lower right corner of the license plate. The license plate is segmented by these two coordinates, and the gray license plate image is adaptively binarized with the OTSU algorithm. The final effect is as follows:

 

80db0d5bbe9d5473929c1bdaf63c2706.png

 

 

 

  1. The third part is character segmentation

The work of this part is to extract the 7 characters in the license plate separately. The method is as follows: Traverse the binary image from left to right by column z, calculate the sum of each column, the sum of columns without white dots is 0, the sum of columns with white dots is non-zero, convert to logic 1, and record all The column and the column converted between 0 and 1 are the columns that need to be cut. There are 14 columns in total, and 7 characters can be cut out. After cutting out a single character, put it into char_(i), and cut off the upper and lower blank areas of each character to complete the precise cutting. The effect is as follows:

 

 

7c54ff222e9ca98e47ccfc9da0432f6b.png

 

 

 

  1. The fourth part is character recognition

The recognition methods mainly include template matching character recognition algorithm, statistical feature matching algorithm, neural network character recognition algorithm and support vector machine pattern recognition algorithm. Because the effect of segmented characters is better, it is obviously distorted, the dimension of the template k is low (32*16), and because of the time relationship, the template matching recognition algorithm is used here. The program subtracts the cut characters from the Chinese characters and character templates in the library, finds the template with the least difference as the corresponding template, outputs the characters corresponding to the template, and finally recognizes it as "Jing JX9168". as follows:

5c7c8cb3f8a852e3dd666e00b7b9bf40.png

2. Code

 

clear all
clc
PS=imread('1.jpg'); 
subplot(1,2,1);
imshow(PS)                                             
title('Original Image')
p=rgb2gray(PS);
subplot(1,2,2)
imshow (p)
title('Original grayscale image')

[m,n]=size(p);  
GP=zeros(1,256);       
for k=0:255
GP(k+1)=length(find(p==k))/(m*n);  
end
figure
subplot(1,2,1);
bar(0:255,GP,'g')                          
title('Original grayscale histogram')

max_index=[];
for i=3:length(GP)-2
if((GP(i)>=GP(i+1))&(GP(i)>=GP(i-1)))&((GP(i+1)>=GP(i+2))&(GP(i-1)>=GP(i-2)))
max_index(end+1)=i-1;
end
end
possible=GP(max_index);
[max_value,index]=max(possible);
TT=max_index(index)-2;

[m,n]=size(p);
R=zeros(m,n);
for i=1:m
    for j=1:n
        if p(i,j)<TT
           R(i,j)=0;
        else R(i,j)=256;
        end
    end
end
subplot(1,2,2);
imshow(R);
title('二值图');

 

3. Running results

01aca1ae40c3414991dc3990ffff8a28.png

 159321c969514251b6839c59005b8fe5.png

 

 

 

Guess you like

Origin blog.csdn.net/m0_57943157/article/details/131604539