License plate Recognition step and part code

Source: Internet
Author: User
Tags bmp image scale image split

Category: Miscellaneous 2013-06-19 14:53 1942 person Reading reviews (0) Favorite Report

Directory (?) [+]

Directory (?) [-] License plate preprocessing character segmentation normalization processing character feature extraction neural network training license plate image recognition result test 1. License plate pre- processing

The process of license plate pretreatment directly affects the post-processing of license plate image, such as the segmentation of license plate characters. License plate pretreatment is also the elimination of noise as much as possible, reducing the unnecessary trouble caused by post-processing.

The imported license plate is 24Bit BMP true Color image, car license plate has yellow black, blue bottom white and other colors, in order to take these license plate image processing, it is necessary to first the license plate grayscale processing, and then binary (black and white) processing.


Figure 4-1 the original image

The acquisition of the license plate image preprocessing, for the sake of convenience, here is a BMP format picture, I will collect the license plate image to be cut, cut the picture as follows:

Because most of China's license plate is the first character, the second to the seventh is a letter or number, which can be the license plate image recognition process is divided into two parts, the first part is the process of recognition of Chinese characters, the second part is the process of identifying letters and numbers, because the Chinese characters more strokes, the same letter or number processing process is different. So I'm going to deal with the process of letters or numbers first.

In addition to the kanji, there is a point between the first letter and the second number, so consider removing the middle point when the character is split. License plate Image Overall is relatively clear, large civil vehicles, the license plate for the yellow black Word, small civil vehicles, license plate for the blue bottom white , because the character and background color contrast is more obvious, so it is easier to separate the license plate. Because some license plate and below also have screws and other things will be fixed plate, so when the license plate segmentation, through the horizontal scanning jumping point method, can be removed, in order to finally partition the license plate, remove the interference.

In the RGB model, if r=g=b, color represents a grayscale color, where the value of r=g=b is called a grayscale value, so grayscale images each pixel only need one byte to hold the grayscale value (also called intensity value, luminance value), gray scale range is 0-255. There are generally four ways to grayscale a color image.

1. Component method. is to extract the color value on each component, which is the RGB3 color. That is: the brightness of the three components in the color image as the gray value of three gray-scale images, you can choose a grayscale image according to the application needs. F1 (I,J) =r (i,j) f2 (i,j) =g (I,j) F3 (i,j) =b (i,j) where FK (I,j) (k=1,2,3) is the grayscale value at (i,j) of the converted grayscale image.

2. Maximum Value method. Select the maximum value of the color in the three components (RGB) in the color image as the grayscale value of the grayscale graph. namely: F (i,j) =max (R (i,j), G (I,j), B (I,j)).

3. Averaging method. The three-component luminance in the color image is averaged to obtain a grayscale figure f (i,j) = (R (i,j) +g (i,j) +b (I,J))/3.

4. Weighted average method. According to the importance and other indicators, the three components are weighted evenly with different weights. Because the human eye is sensitive to the green, the sensitivity of the blue is the lowest, so the weighted average of the RGB three components can get a more reasonable gray-scale image. F (i,j) =0.30r (i,j) +0.59g (i,j) +0.11b (i,j)).


Above four kinds of processing, in the process of license plate pretreatment, I choose the weighted average value method. The effect is as follows:


Figure 4-2 Original image Figure 4-3 grayscale image

As shown above, it is a grayscale image that is processed with the weighted average of the original image in the diagram.

The key code is as follows:

for (i = 0;i < Height; i++)

{

for (j= 0;j < width*3; j+=3)

{

ired = (unsigned char*) lpdibbits + linebytes* i + j + 2;

igreen= (unsigned char*) lpdibbits + linebytes * i + j + 1;

Iblue = (unsigned char*) lpdibbits + linebytes* i + j;

lpdest[i*width+ j/3]= (unsigned char) ((*ired) *0.299 + (*igreen) *0.588 + (*iblue) *0.114);//Weighted average calculation processing

}

}

Binary processing. Binary processing the BMP image is processed in black and white, so that the background is separated from the character area. Since the grayscale image is a color value between 0-255. The process of binary processing is to divide the color of this image into black values of 0 and white values of 2,552 colors. To separate the background from the license plate character, set a threshold value. Setting thresholds is key. If the chosen threshold value of two is inappropriate, it may not be possible to distinguish the background of the license plate image from the text, so the threshold selection of the binary value is very important. According to the test, I set a threshold value of
125. The results of the binary are as follows:


Figure 4-7 Two after the value of the image

The above image is a test of the two-value effect of the license plate image for white and yellow black characters on blue background. After the image is binary, the background can be clearly separated from the license plate character.

The key codes for binary processing are as follows:

for (i = 0; i < Height; i++)//per line

{

for (j = 0; J < Width; J + +)/per column

{

Pointer to the first line of the DIB, J-Pixel

LPSRC = (unsigned char*) lpdibbits+linebytes * (LHeight-1-i) + j;

Determine if it is less than the threshold value

if ((*LPSRC) < Bthre)

{

*LPSRC = 0; The direct assignment is 0, which is black

}

Else

{

*LPSRC = 255; The direct assignment is 255, which is white

}

}

} 2. Character Segmentation

As the license plate image has been refined, the horizontal scan and the vertical scan can be used to separate the characters, the horizontal scan determines the upper and lower limits of the picture, and the vertical scan can determine the left and right coordinates of the characters in the picture. According to the characteristics of the license plate, the license plate image of the horizontal scanning jumping point, that is, the horizontal adjacent two pixels, if not the same is considered to have a jumping point, the number of records plus 1, because the license plate sometimes has two white spots, so by judging the number of jumping points, you can remove the above two white spots [9]. As shown in the figure, the jumping points of the scan processing are as follows:


Figure 4-10 The original image with two white dots on it


Figure 4-11 Statistics of the number of jumping points in a horizontal scan

Statistical results: 4 4 4 0 0 14 14 16 20 24 24 24 24 22 20 24 26 28 28 30 2626 24 20 20 22 22 22 26 20 20 22 24 20 20 20 20 2 0 4 4 6 4 image Of Number of scan results quantity is the number of license plate height.

From the top down, according to the experimental results, set when the horizontal jumping point more than 10, as the limit of the license plate character interception. When looking from the bottom up, when the jumping point more than 8 can be used as the lower limit of the license plate character interception. The upper and lower parts of the license plate can be determined by the above procedure. Similarly, the segmentation of license plate characters around the boundary, through the vertical scanning process, because the numbers and letters have connectivity, so it is easier to split numbers and letters. Through the vertical scanning process, the number of black pixels is counted, because there is no black pixel between two characters, so it can be used as the boundary of character segmentation. The vertical scanning process is shown below:


Shaanxi A. 5 P 0 7 2

Figure 4-12 The number of black pixels in a vertical scan license plate character


The above statistics make it easy to separate the character boundary. You can separate characters by horizontally scanning the jump points and scanning the pixel points vertically. But there are some problems. For example, some Chinese characters are not unicom, such as "Shaanxi" word, the left ear and the right side of the "clip" word, sometimes scanning will have gaps, so I here in scanning the first Chinese characters, to add some processing, when the "Shaanxi" left ear width is not the total width of 1/12 times, I continue to scan down until the zero pixel. And there's a "." Between A and 5. Number, which can be scanned by a width not 3/8 of the width, I can think of as the middle "." No. So through the above processing, most of the license plate image characters can be segmented. The effect of the character segmentation is shown in the following figure:

Figure 4-13 Character segmentation image

The key code for character segmentation is as follows:

If the distance is less than 1/12 of the width, it is counted as invalid

Intwid = LWIDTH/13;

intxx=0,pos=0;

Intflag = 0;

intsuccess = 0;

for (i=0;i<lwidth;)

{

while (vcount[i]==0) i++;

if ((i-1) <0)

Posi[k++]=i;

Else

Posi[k++]=i-1;

xx=0;

while (vcount[i]!=0&& i<lwidth) i++;

if (flag==0)

{

Pos= i;

while (vcount[i]==0) {i++;xx++;}

if (xx < (WID/4))

{

Str. Format ("xx=%d wid/4=%d i=%dposi[k-1]=%d", xx,wid/4,i,posi[k-1]);

MessageBox ("Chinese characters have a split" +str);

xx=0;

while (vcount[i]!=0) {i++;xx++;}

if (xx<=8)

{

xx= 0;

while (vcount[i]==0) {i++;xx++;}

if (xx< (LWIDTH/16))

while (vcount[i]!=0 && i< (LWIDTH/8)) i++;

}

}

Else

{

i= POS;

}

}

flag=1;

if (i>= lwidth)

{

Posi[k++]=i-1;

}

Else

{

posi[k++]=i+1;

}

If the character is the second and third character in the middle of the point, remove. If it is 1, the width increases

if (POSI[K-1]-POSI[K-2]<=WID)

{

if (i<= (lwidth/8*3))

{

Intx = Posi[k-1]-posi[k-2]; K=k-2;

Str. Format ("%d%d%d%d", x,wid,i,bottomline-topline);

}

Else

{

Posi[k-1]= POSI[K-1]+WID/3;

Posi[k-2]= POSI[K-2]-WID/3;

}

}

if (k>=14)

{

Success= 1;

Break

}

}

if (success== 0)

{

MessageBox ("Character separation error, program end identification process!");

} 3. Normalization of processing

The quality of character segmentation is related to the key of normalization processing in the back. If the character segmentation is not established, the normalization process will not succeed. At the beginning of the experiment, I first carried out the refinement of processing, and then the normalization process, but after normalization processing has, the character basically lost the original skeleton structure, so I here first to normalization processing.


The so-called normalization process is to divide characters into different sizes, so the characters are normalized to an image of 25x50 pixel size. Image x-axis scaling ratio is, y-axis scaling ratio, the original image width and height of lwidth,lheight[12]. The scaling ratio is determined by the formula:


In the process of zooming in or out of an image, the resulting pixel may not be able to find the corresponding pixel in the original. This means that the interpolation process must be used. There are two general interpolation methods, one is the direct assignment to its nearest pixel value, the other is the interpolation algorithm to calculate the corresponding pixel value. The first method of calculation is simpler and more efficient, but the effect is not very good, such as sometimes mosaic phenomenon, so, the second method, although the budget is a bit complex, but the final normalized character will not be distorted. To the back to do a refinement process to pave the way. It is found that the bilinear interpolation method is better than the nearest neighbor interpolation method, so the normalized bilinear interpolation method is used in this paper.

Figure 4-14 above for the original image binary results, the following image is normalized results

The normalized key code is as follows:

operate on each line of the image

for (i= 0; i < newheight; i++)

{

operate on each column of the image

for (j= 0; J < Newwidth; J + +)

{

Pointer to the first line of the new Dib, J-Pixel

Note that the width and height here are the width and height of the new DIB

LPDST = (char*) lpnewdibbits + newlinebytes * (NewHeight-1-i) + j;

X= J/fxzoomratio;

Y= I/fyzoomratio;

if (tag)

                             {    //tag=1, the following nearest neighbor interpolation code is executed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.