Realization of License Plate Recognition System Based on Matlab

1. Project Background and Objectives

        With the improvement of people's living standards, the number of motor vehicles is gradually increasing. In 2020, the total number of motor vehicles in the country is 372 million, of which the number of cars is 281 million, accounting for 75.54%. Such a huge number of cars has brought great pressure to the management of the transportation industry. Relying on manual road management requires heavy workload and high error rate. Therefore, it is necessary to find an effective method to improve the management efficiency of vehicles, thereby reducing the pressure of road driving. Vehicle license plate, because of its uniqueness, becomes the key to solve the above problems.

        Based on the vehicle license plate, this project designed a vehicle license plate recognition system (Vehicle License Plate Recognition, VLPR) based on matlab software, which can detect vehicles on the monitored road and automatically extract vehicle license plate information (Chinese characters, English letters, Arabic numerals). The system can be used in road monitoring, community vehicle registration, parking lot vehicle registration, highway electronic toll collection and other scenarios, providing convenience for road traffic management.


2. System description

        The license plate recognition system (VLPR) designed in this project mainly realizes the function of extracting the license plate information from the image and outputting it to the operation interface. The input of the system is a picture containing license plate information, and the output is the license plate information of the vehicle in the picture. The license plate recognition system code can be divided into three parts, namely image preprocessing, image cutting, and character recognition (as shown in Figure 1). Next, the content of the three parts will be described in turn.

Figure 1 System flow chart

 2.1 Image preprocessing

         Since the image information elements input by the system are too many and the quality levels are not uniform, it is impossible to directly locate the position of the license plate and cut it, so preprocessing is required. The function of image preprocessing is to pre-process the input image of the system to provide the basis for the next step of image cutting.

2.1.1 Basic steps of preprocessing

        The main methods of image preprocessing in this system are: image enhancement, image morphology processing, extraction of specific channel information, etc.

        1) Image enhancement

        The main operations involved in image enhancement are contrast enhancement and image binarization.

        Image contrast refers to the measurement of different brightness levels between the brightest white and the darkest black in the light and dark areas of the image. The larger the difference range, the greater the contrast, and the smaller the difference range, the smaller the contrast. In the process of image preprocessing, increasing the contrast of the original image can effectively filter out useless information and make the target-related information more visually obvious. Improving the contrast means increasing the difference between the gray levels of each level, which is conducive to image binarization processing.

        In the matlab software, the contrast enhancement operation can be realized through the imadjust function.

        Image binarization is to compare the gray value of the pixel in the picture with the set threshold. If the gray value is greater than the threshold, the gray value is updated to 255, otherwise, it is updated to 0. The image after the above operations will only display black and white visual effects. The grayscale of a pixel has only two values ​​of 0 and 255, so it is called binarization. The operation of image binarization can effectively filter out image background, noise and other information through threshold setting, and extract effective information related to the target object.

        In the matlab software, the image binarization operation can be realized through the im2bw function.

        2) Image Morphological Processing

        Image morphology processing mainly involves operations such as image dilation, image erosion, opening operation, closing operation, top hat operation, and bottom hat operation. This system does not use the latter two operations, so it will not be introduced.

        Image dilation and erosion is the basic method of morphological processing. The expansion of the image selects the largest gray value in the neighborhood of each pixel as the output gray value. After expansion, the overall brightness of the image will increase, the size of brighter objects in the image will increase, and the size of darker objects will decrease. or even disappear, resulting in an "inflated" visual effect. The erosion of the image is opposite to the expansion. The smallest gray value in the neighborhood of each pixel is selected as the output gray value. Dark objects grow in size, giving a "corroded" visual effect.

        In matlab, by setting the parameter se, the imdilate function can be used to complete the image expansion operation, and the imerode function can be used to complete the image erosion operation.

        The image opening and closing operations are combined by erosion and dilation. The opening operation is to corrode the image first and then expand it. It can eliminate small areas with high brightness, separate objects at thin points, and smooth the boundary of larger objects without changing their area. The closing operation is to expand the image first and then corrode it, which can fill the small black area in the white object and connect the detailed white area.

        In matlab, you can use the imopen function to complete the image opening operation and use the imclose function to complete the image closing operation by setting the parameter se.

        3) Extract specific channel information

        There are many ways for the computer to record images, the most common one is the RGB model, and the HSV model will also be used in this system.

        The RGB color model displays images through the data of the three color channels of red (Red), green (Green), and blue (Blue) and their mutual superposition. This system is mainly used to identify small cars. According to the provisions of the People's Republic of China motor vehicle license plate "GA 36-2014", small car license plates are "white characters on a blue background". Based on this information, the RGB model can be used to extract the The relevant elements of the blue color block, so as to extract the effective elements (license plate) in the image.

        The HSV color model is a color model created by AR Smith. Think of a picture as the superposition of the three channel information of hue (Hue), saturation (Saturation), and lightness (Value). After a large number of experiments, it was found that the data of the S channel can effectively display the license plate information and distinguish it from the surrounding background. Therefore, when designing the system, the S channel information is often extracted.

 2.1.2 System pretreatment scheme

Figure 2 Preprocessing flow chart

        The image preprocessing process of this system can be divided into four steps (as shown in Figure 2). First import the image and reset the image size, and then perform image processing operations such as extracting channel information, image enhancement, and morphological processing. After the above steps are completed, feature extraction is performed based on the processed image to extract the blue area. Perform image processing operations such as extracting channel information, image enhancement, and morphological processing again, and finally output the image to complete the preprocessing.

      1 ) Import pictures, reset picture size

      Use the imread function in the matlab software to input pictures. Due to the different resolutions of imported pictures, it is not conducive to post-processing and cutting. Use the imresize function to adjust the image size, and adjust all input images to a size of 1000*1000.

% 导入图像,将图像像素设置为1000*1000
image = imread('.\target\4.jpg');
im1 = imresize(image, [1000, 1000]);
pic = im1;
figure(1)
subplot(3, 3, 1); imshow(im1);

      2 ) The first image processing

      Image processing mainly includes three parts: extracting S-channel information, image enhancement, and morphological operations. The main functions used are: rgb2hsv, imadjust, imclose, imdilate, bwareaopen, etc. The functions of the above three parts have been explained in Section 2.1.1, and will not be repeated here. The processing results are shown in Figure 3.

(a) input image
(b) Extract S channel information
(c) Image enhancement
(d) Morphological processing

Figure 3 Image processing effect diagram

% 提取图象 S 通道信息
fig1 = rgb2hsv(im1);
im2 = fig1(:, :, 2);
subplot(3, 3, 2); imshow(im2);

% 增强图像对比度,并进行二值化
im3 = imadjust(im2);
im4 = im2bw(im3);
subplot(3 ,3, 3); imshow(im4);

% 对图像进行闭运算,并提取二值化图像中的白色部分
se1 = strel('rectangle', [20, 20]);
im5 = imclose(im4, se1);
[m ,n] = size(im5);
for i = 1:m
    for j = 1:n
        if im5(i, j) == 0
            pic(i, j, :) = 255;
        end
    end
end
im6 = pic;
subplot(3, 3, 4); imshow(im6);

        3) Extract the blue area

        It can be seen from Figure 2 that after an image processing operation, the license plate information can be extracted better, but due to the interference of the environment, some background information will also be mixed in it, so it is necessary to extract the license plate information according to the "blue background and white characters" of the small vehicle license plate. " feature, extract the blue part of the image, and further filter the noise.

        For the image output after image processing, the data of the three color channels are first divided according to the RGB model, stored in the preset matrix, and then each pixel in the three matrices is traversed. Determine whether the pixel is blue by setting the judgment condition. If it is blue, keep the position data unchanged; if it is not blue, set the pixel data to 255. After the above processing, the blue area in the image will be preserved, and the non-blue area will be white.

        The key point of this step is the setting of the judgment conditions. Since the input photos have different colors and lighting conditions, it is difficult to find the judgment conditions that can satisfy all the pictures. After a lot of experiments, the system sets the judgment condition as "the blue value of the pixel point is less than 65, and the red and green values ​​are greater than 100", which can meet most scenes. The processing results are shown in Figure 4.

(a) Output map of the first image processing
(b) Extract the blue area

Figure 4 Extraction of blue area renderings

% 对图像中蓝色区域进行提取
im6r = im6(:, :, 1);
im6g = im6(:, :, 2);
im6b = im6(:, :, 3);
for i = 1:m
    for j = 1:n
        if im6b(i, j)<65 || im6r(i, j)>100 || im6g(i, j)>100
            pic(i, j, :) =255;
        end
    end
end
im7 = pic;
subplot(3, 3, 5); imshow(im7);

      4 ) The second image processing

      Considering that in the image, there may be blue parts other than the license plate, or non-license plate parts that meet the above judgment conditions, which will cause interference in the subsequent image cutting and character recognition process, so the second image processing process is set. The function is basically the same as the function used in the first image processing, combined with the actual situation, a change was made in the selection of specific parameters. The processing result is shown in Figure 5

(a) Extract the output map of the blue area
(b) Image enhancement
(c) Image binarization
(d) Morphological processing

Figure 5 Effect diagram of secondary image processing

% 提取新图象 S 通道信息
fig5 = rgb2hsv(im7);
im8 = fig5(:, :, 2);
subplot(3, 3, 6); imshow(im8);

% 增强新图像对比度,并进行二值化
se2 = [0 1 0; 1 1 1; 0 1 0];
fig4 = imdilate(im8, se2);
fig5 = imdilate(fig4, se2);
im9 = imadjust(fig4);
im10 = im2bw(im9);
subplot(3 ,3, 7); imshow(im10);

% 对提取图像进行膨胀处理,进一步提取特征,为保证下一步切割顺利,再次进行闭运算。
fig2 = imdilate(im10, se2);
fig3 = imdilate(fig2, se2);
im11 = bwareaopen(fig3, 4000);
im12 = imclose(im11, se1);
subplot(3, 3, 8); imshow(im12);

      Although the secondary image processing effect in Figure 5 is remarkable, it can be observed that there is a large amount of noise information around the license plate in Figure 4-(a), which has completely disappeared after secondary image processing, and only in the license plate part in Figure 4-(d) Has a white visual effect.

      To sum up, after the image preprocessing process shown in Figure 2, the useless information in the input image is fully filtered, and the key license plate information is preserved, laying the foundation for subsequent image cutting and character recognition.


2.2 Image Slicing

        After the system input image is pre-processed, the license plate information is retained, and invalid information is filtered out to the greatest extent. The operation to be completed in image cutting is to first cut the whole license plate according to the preprocessed information, and then cut individual characters, so as to facilitate character recognition in the next step.

      Image cutting is the most important part of this system, its flow chart (as shown in Figure 6), the input of this part is the image after preprocessing, and the output is 7 character images containing license plate information. The accuracy of this portion of cutting directly affects the accuracy of character recognition. If there is a problem in the cutting link, no matter what kind of character recognition method is adopted, it will not help. Next, the license plate cutting, character rough cutting, and character fine cutting are introduced respectively.

Figure 6 Flow chart of image cutting

 2.2.1 License plate cutting

    The function implemented in this part is to position and cut the license plate on the basis of the preprocessed image. It can be seen from Figure 5-(d) that after preprocessing, the license plate position in the image is displayed as white, and the rest are displayed as black, but in some cases there may be a small area of ​​white area in the non-license plate position. The license plate cutting part traverses all the pixels of the image, sets the judgment conditions, and records the coordinate values ​​of the pixels that meet the judgment conditions in the array. After recording the data of all pixel points, search for the data that meets the requirements in the array, so as to determine the position of the cutting point, and use the imcrop function in matlab to cut.

      According to the analysis of the usage of the imcrop function, the key coordinate positions are the upper left corner and the lower right corner of the license plate. The characteristic of the upper left corner of the license plate is that the data of the pixel itself is 1, and there are many pixels with the data of 1 in the lower right. Therefore, based on this, the judgment conditions for finding the coordinates of the upper left corner of the license plate are set. Similarly, the characteristic of the lower right corner of the license plate is that the pixel itself has a data of 1, and there are many pixels with a data of 1 in the upper left corner. Based on this, set the judgment condition for finding the coordinates of the lower right corner of the license plate.

      Among all coordinate points that meet the requirements, the sum of the horizontal and vertical coordinates of the coordinate point in the upper left corner must be the smallest, and the sum of the horizontal and vertical coordinates of the coordinate point in the lower right corner must be the largest. Based on this, it is enough to find the coordinate points that meet the requirements in the array. Considering that the car license plate has a white border, it may affect the next cutting step, so the upper left coordinate point is slightly moved to the lower right direction, and the lower right coordinate point is slightly moved to the upper left, so as to obtain the cutting point of the license plate.

      Use the above logic to find the upper left corner and lower right corner of the license plate in the image, and cut them. The effect is shown in Figure 7.

(a) Preprocess the output image

(b) license plate cutting diagram

Figure 7 license plate cutting effect

 

% 寻找车牌位置
p1 = zeros(5000, 2);
h1 = 1;
for i = 1: m-51
    for j = 1: n-81
        if im12(i, j) == 1
            for k = 1:10
                if im12(i, j+k) == 1 && im12(i+k, j) == 1  && im12(i, j+70+k) == 1 && im12(i+40+k, j) == 1 
                    p1(h1, 1) = i;
                    p1(h1, 2) = j;
                    h1 = h1+1;
                end
            end
        end
    end
end

for i = 1:500
    if p1(i, 1) == 0 && p1(i, 2) == 0
        p1(i, 1) = m+n;
    % elseif abs(p1(i, 2) - n/2)*2/n > 0.95 || abs(p1(i, 1) - m/2)*2/m >0.95
    %    p1(i, 2) = m+n;  
    end
end

s1 = sum(p1,2);
min1 = min(s1);
[row1, column1] = find(s1 == min1);
X1 = p1(row1, 1);
Y1 = p1(row1, 2);

p2 = zeros(5000, 2);
h2 = 1;
for i = 51: m
    for j = 81: n
        if im12(i, j) == 1
            for k = 1:10
                if im12(i, j-70+k) == 1 && im12(i-40+k, j) == 1 && im12(i, j-k) == 1 && im12(i-k, j) == 1
                    p2(h2, 1) = i;
                    p2(h2, 2) = j;
                    h2 = h2+1;
                end
            end
        end
    end
end

for i = 1:500
    if p2(i, 1) == 0 && p2(i, 2) == 0
        p2(i, 1) = -m-n;
    % elseif abs(p2(i, 2) - n/2)*2/n > 0.95 || abs(p2(i, 1) - m/2)*2/m >0.95
    %    p2(i, 1) = -m-n;  
    end
end

s2 = sum(p2,2);
max1 = max(s2);
[row2, column2] = find(s2 == max1);
X2 = p2(row2, 1);
Y2 = p2(row2, 2);

% 定义裁剪区域并进行裁剪
x1 = min(X1)+4;
y1 = min(Y1)+4;
x2 = max(X2)-4;
y2 = max(Y2)-4;
rect = [y1, x1, y2-y1, x2-x1];
im13 = imcrop(im4, rect);
 figure(2)
 imshow(im13)

2.2.2 Character rough cutting

        The main functions realized in this part are based on the license plate cutting, according to the provisions of the license plate character position in the motor vehicle license plate "GA 36-2014" of the People's Republic of China (as shown in Figure 8), combined with the actual size of the license plate cutting output image, Use the imcrop function to cut the picture again, and save the cutting results in the three-dimensional matrix in turn.

Figure 8 Standard pattern of license plate

 

The effect of character rough cutting according to the above criteria is shown in Figure 9.

(a) License plate cutting output image
(b) Rough cutting of characters

Figure 9 Rough cutting effect diagram of characters

% 参照车牌国际标准,进行第一次分割,并将切割结果放入im14中
[m, n] = size(im13);
n1 = 0.1511*n;
n2 = 0.2807*n;
n3 = 0.3307*n;
n4 = 0.4602*n;
n5 = 0.5898*n;
n6 = 0.7193*n;
n7 = 0.8489*n;

rect1 = [0, 0, n1, m];
rect2 = [n1, 0, n2-n1, m];
rect3 = [n3, 0, n4-n3, m];
rect4 = [n4, 0, n5-n4, m];
rect5 = [n5, 0, n6-n5, m];
rect6 = [n6, 0, n7-n6, m];
rect7 = [n7, 0, n-n7, m];

 figure(3)
pic1 = imresize(imcrop(im13, rect1), [100, 50]);  im14(:, :, 1) = pic1(:, :);
     subplot(1, 7, 1); imshow(im14(:, :, 1));
pic2 = imresize(imcrop(im13, rect2), [100, 50]);  im14(:, :, 2) = pic2(:, :);
     subplot(1, 7, 2); imshow(im14(:, :, 2));
pic3 = imresize(imcrop(im13, rect3), [100, 50]);  im14(:, :, 3) = pic3(:, :);
     subplot(1, 7, 3); imshow(im14(:, :, 3));
pic4 = imresize(imcrop(im13, rect4), [100, 50]);  im14(:, :, 4) = pic4(:, :);
     subplot(1, 7, 4); imshow(im14(:, :, 4));
pic5 = imresize(imcrop(im13, rect5), [100, 50]);  im14(:, :, 5) = pic5(:, :);
     subplot(1, 7, 5); imshow(im14(:, :, 5));
pic6 = imresize(imcrop(im13, rect6), [100, 50]);  im14(:, :, 6) = pic6(:, :);
     subplot(1, 7, 6); imshow(im14(:, :, 6));
pic7 = imresize(imcrop(im13, rect7), [100, 50]);  im14(:, :, 7) = pic7(:, :);
     subplot(1, 7, 7); imshow(im14(:, :, 7));

 2.2.3 Character precision cutting

        The main function of this part is to further cut the characters based on the rough cutting to get the character image without edges (characters occupy the entire image space). The step of fine character segmentation is of great significance to character recognition based on template matching.

      Due to the existence of license plate borders, there are more or less black edges on the edges of the seven images after rough cutting. The analysis of the images shows that black edges may appear on the left edge, upper edge, and lower edge of the first image. Black borders may only appear on the top and bottom of the 6 images, and black borders may appear on the right, upper, and lower edges of the seventh image. In order to improve the accuracy of cutting and avoid the timeliness reduction caused by complicated procedures, the following processing methods are decided.

      The 2nd to 6th pictures are all letters or numbers, which are continuous structures, and only have black borders on the upper and lower edges. Therefore, the method of "first up and down, then left and right, from the middle to both sides" is adopted for cutting. "First up and down, then left and right" means to find the upper and lower boundaries of the cutting first, and cut them, and then find the left and right boundaries of the cutting, and then cut again. "From the middle to both sides" means that each search traverses from the middle of the image to both sides. Since letters and numbers are continuous structures, this method can be used to avoid the influence of black borders to a certain extent. . Since the upper and lower edges of these rough-cut pictures have black borders, and there are no black borders on the left and right edges, start from the middle row of the image and search for the data of each row upwards. The data of white pixels in the image is 1, and the data of black pixels is 0. When a black pixel is encountered, the counter is incremented by 1. From this point of view, when the counter becomes 0 (or less than a preset value to enhance applicability) when a certain line is reached, it can be judged that there are no black pixels in this line, and this line is the upper boundary of cutting. Similarly, the lower boundary of the cut can be found. Use the imcrop function to complete the cutting of the upper and lower blank areas and black edges of the image. At this time, there is no black edge effect on the top and bottom of the image. It is the same as finding the upper and lower boundaries. You can refer to the above principle to find the left and right boundaries of the image, and then use the imcrop function to complete the fine cutting of the image.

      The seventh image is also a number or letter, but unlike the previous one, it has more complex black edge interference, so the black edge should be cut off first, and then the characters should be extracted using the same fine cutting method as before. Cutting off the black edge adopts the method from both sides to the middle, starting from the top row, searching down the data of each row, every time a black pixel is encountered, the counter is incremented by 1, when the counter value is 0 (or less than a certain preset value , to enhance the applicability), it can be considered that the black edge has been eliminated, then set the upper limit of this behavior, and similarly, you can find the lower limit and perform a cut. Then compare the above method to find the left and right cutting lines, and complete the operation of removing the black edge. After removing the black edges, follow the cutting method of the 2nd to 6th images to complete the fine cutting of the 7th image.

      The 1st image has complicated black edges and the characters are Chinese characters. First, cut off the black edge. The cutting method used is the same as the cutting method of the seventh image. After the cutting is completed, the characters are ready to be finely cut. Since Chinese characters are not continuous, the method of "from the middle to both sides" cannot be adopted. Cutting method, so we use the conventional search method of "from both sides to the middle". The specific implementation method is similar to "from the middle to both sides", except that the search direction is changed and the judgment conditions are adjusted accordingly. I won't repeat them here. Finally, save the 7 images after cutting in a 3-dimensional matrix.

      Figure 10 shows the effect of fine-cutting the characters.

(a) Character fine-cut input image
(b) Character fine cutting output image

Figure 10 Character fine cutting renderings

for k = 1: 7
    
    % 首先对首尾字符进行处理
    if k == 1 || k == 7
        piccut = im14(:, :, k);
        [m, n] = size(piccut);
        m1 = 0; m2 = 0;
        
        %搜索裁剪的上边界
        for i = 1: 1: m/2
            count1 = 0;
            for j = 1: n
                if piccut(i, j) == 0
                    count1 = count1+1;
                end
            end
            if count1 <= 6
                m1 = i+4;
                break
            end
        end
        
        %搜索裁剪的下边界
        for i = m: -1: m/2
            count2 = 0;
            for j = 1: n
                if piccut(i, j) == 0
                    count2 = count2+1;
                end
            end
            if count2 <= 6
                m2 = i-4;
                break
            end
        end
        if m2 == 0;
            m2 = m;
        end
        
       % 首先根据行数,做高度方向的裁剪
        rect10 = [0, m1, n, m2-m1];
        im15 = imcrop(piccut, rect10);
        [m, n] = size(im15);
        n1 = 0; n2 = 0;
        
        % 搜索裁剪的左边界
        for j = 1: 1: n/2
            count3 = 0;
            for i = 1: m
                if piccut == 0
                    count3 = count3+1;
                end
            end
            if count3 <= 6
                n1 = j+4;
                break
            end
        end
        
        % 搜索裁剪的右边界
        for j = n: -1: n/2
            count4 = 0;
            for i = 1: m
                if piccut(i, j) == 0
                    count4 = count4+1;
                end
            end
            if count4 <= 6
                n2 = j-4;
                break
            end
        end
        if n2 == 0;
            n2 = n;
        end
        
        % 对图像进行二次处理
        rect11 = [n1, 0, n2-n1, m];
        im16 = imresize(imcrop(im15, rect11), [100,50]);
        im14(:, :, k) = im16;
    end
    
    % 搜索图像切割边界
    picpro = im14(:, :, k);
    [m, n] = size(picpro);
    m1 = 0; m2 = 0;
    
    if k == 1
        
        % 搜索切割的上边界
        for i = 1: 1: m/2
            count1 = 0;
            for j = 1: n
                if picpro(i, j) == 0
                    count1 = count1+1;
                end
            end
            if count1 >= 5
                 m1 = i+1;
                 break
            end
        end

        % 搜索切割的下边界
         for i = m: -1: m/2
            count2 = 0;
            for j = 1: n
                  if picpro(i, j) == 0
                      count2 = count2+1;
                  end
            end
            if count2 >= 5
                m2 = i-1;
                break
            end
        end
        if m2 == 0
            m2 = m;
        end

        % 首先根据行数,做高度方向的裁剪
        rect12 = [0, m1, n, m2-m1];
        im17 = imcrop(picpro, rect12);
        [m, n] = size(im17);
        n1 = 0; n2 = 0;

        % 寻找切割的左边界
        for j = 1: 1: n/2
            count3 = 0;
            for i = 1: m
                if im17(i, j) == 0
                    count3 = count3+1;
                end
            end
            if count3 >= 6
                n1 = j+1;
                break
            end
        end

        % 寻找切割的右边界
        for j = n: -1: n/2
            count4 = 0;
            for i = 1:m
                if im17(i, j) == 0
                    count4 = count4+1;
                end
            end
            if count4 >= 6
                n2 = j-1;
                break
            end
        end
        if n2 == 0;
            n2 = n;
        end

        % 完成切割工作
        rect13 = [n1, 0, n2-n1, m];
        im18 = imresize(imcrop(im17, rect13), [40, 20]);
        fipic(:, :, k) = im18;
        
    else
        % 搜索切割的上边界
        for i = m/2: -1: 1
            count1 = 0;
            for j = 1: n
                if picpro(i, j) == 0
                    count1 = count1+1;
                end
            end
            if count1 <= 5
                 m1 = i+1;
                 break
            end
        end

        % 搜索切割的下边界
         for i = m/2: 1: m
            count2 = 0;
            for j = 1: n
                  if picpro(i, j) == 0
                      count2 = count2+1;
                  end
            end
            if count2 <= 5
                m2 = i-1;
                break
            end
        end
        if m2 == 0
            m2 = m;
        end

        % 首先根据行数,做高度方向的裁剪
        rect12 = [0, m1, n, m2-m1];
        im17 = imcrop(picpro, rect12);
        [m, n] = size(im17);
        n1 = 0; n2 = 0;

        % 寻找切割的左边界
        for j = n/2: -1: 1
            count3 = 0;
            for i = 1: m
                if im17(i, j) == 0
                    count3 = count3+1;
                end
            end
            if count3 <= 6
                n1 = j+1;
                break
            end
        end

        % 寻找切割的右边界
        for j = n/2: 1: n
            count4 = 0;
            for i = 1:m
                if im17(i, j) == 0
                    count4 = count4+1;
                end
            end
            if count4 <= 6
                n2 = j-1;
                break
            end
        end
        if n2 == 0
            n2 = n;
        end

        % 完成切割工作
        rect13 = [n1, 0, n2-n1, m];
        im18 = imresize(imcrop(im17, rect13), [40, 20]);
        fipic(:, :, k) = im18;
    end
    
    %创建路径保存并展示
    name = 'VLPR';
    datasavename = [name datestr(now, 5) datestr(now, 7)];
    mkdir(datasavename);
    save(['.\' datasavename '\',num2str(k),'.jpg'],'im18')
    figure(4)
    subplot(1, 7, k); imshow(im18);
end

2.3 Character recognition

        The system uses template matching method to realize character recognition. The primary task of template matching is to establish a character template library, collect relevant character pictures on the Internet, use the modelget.m program to convert the pictures into the "white background black" style required by the system, and finally complete the numbers 0-9, letters AZ , and Chinese characters, a template with a total of 67 characters is established. Number the character templates, where numbers 0-9 correspond to serial numbers 1-10, letters AZ (without O, I) correspond to serial numbers 11-34, Chinese characters correspond to serial numbers 35-65, and create a table codebook corresponding to characters and serial numbers. xlsx, codebooknum.xlsx. According to the 5.8 serial number coding rules and usage rules of the People's Republic of China Motor Vehicle Good Standard "GA 36-2014", the letters O and I cannot appear on the license plate, so there is no need to set up a specific program to distinguish between 0 and O, 1 and I .

      When performing character recognition, first set the scope of the search template according to the image features. The first image is Chinese characters, so the search range corresponding to the template serial number is 35-65, the second image is English letters, so the search range corresponding to the template serial number is 11-34, and the third to seventh images are letters or numbers, so the search range corresponding to the template serial number is 1-34. Compare the character image to be recognized with the pixels of the template within the search range one by one, record the number of consistent pixels, and store the data in the corresponding position of the array. When the character image to be recognized has been compared with the templates within the search range, and the comparison data have been recorded in the array, the template corresponding to the maximum value in the array is the most likely real character of the image. The license plate data in the image can be obtained by repeating this cycle seven times, and finally the recognized license plate data can be output (as shown in Figure 11).

Figure 11 Effect diagram of character recognition

2.4 Summary

        To sum up, after the three steps of image preprocessing, image segmentation, and character recognition, the input image of the system can recognize the license plate information in the image and output it. The functions of the license plate recognition system have been realized, and the project goals proposed in "Project Background and Goals" have been met.


3 Limitations of the system 

3.1 Recognition of Chinese characters

        In order to prevent the forgery of the license plate, the font of the license plate in our country is not made public, so the character templates are all searched for pictures on the Internet by myself and completed by myself, which still has a certain gap with the standard font. During the image processing process, due to the uneven quality of the captured pictures, Chinese characters may become blurred after preprocessing, image cutting and other steps. During character recognition, the Chinese characters are not clear, and the Chinese character template is not standard, which may lead to the failure of the Chinese character recognition in the license plate.

3.2 Recognition of blue license plate

        An important step in the image preprocessing process is to extract the blue area in the image. For this purpose, the judgment condition of "the blue value of the pixel point is less than 65, and the red and green values ​​are greater than 100" is set. However, if there are More elements of the same color as the license plate (such as blue vehicles) will invalidate this step, resulting in the inability to recognize the license plate information in the image.

3.3 UI interface design

        Due to time constraints and the approaching exam week, no suitable UI interface was designed for the system, making the operation of the system rather blunt, cumbersome, and unintuitive.

Guess you like

Origin blog.csdn.net/weixin_43725910/article/details/121367448