The process of License Plate Recognition can be divided into three steps: License Plate positioning, character segmentation, and character recognition.
You can perform the following steps to create a subdivision:
(1) grayscale and binarization Images
(2) remove noise and cut it into one character
(3) extract features of each character and generate feature vectors or feature Matrices
(4) Classification and learning. Compare the feature vector or feature matrix with the sample database, select a similar sample, and use the value of this sample as the output result.
License Plate positioning can be referred here. There are also a lot of discussions on this issue on the Internet. Theoretically, it is feasible, but it has not actually been operated. You can try again when you are free.
Http://blog.csdn.net/sing_sing/archive/2010/10/13/5937725.aspx
In the past few days, we have studied the character segmentation problem of license plates, provided that we have pre-processed License Plate positioning and angle correction.
The main knowledge used is binarization, morphological operation, and contour search.
The number of online character segmentation materials is relatively small. I have been in contact with opencv for a while, and I have made some suggestions on it. I hope to discuss it with you.
The following are all source code:
// ================================================ ==========
// Write by sing
// 2010-10-10
// ================================================ ==========
# Include "stdafx. H"
// Find the leftmost end of the text containing the license plate
Void findx (iplimage * IMG, int * min, int * max)
{
Int found = 0;
Cvscalar maxval = cvrealscalar (IMG-> width * 255 );
Cvscalar val = cvrealscalar (0 );
Cvmat data;
Int mincount = IMG-> width * 255/5;
Int COUNT = 0;
For (INT I = 0; I width; I ++ ){
Cvgetcol (IMG, & Data, I );
Val = cvsum (& data );
If (Val. Val [0] <maxval. Val [0]) {
Count = Val. Val [0];
If (count> mincount & count width * 255 ){
* Max = I;
If (found = 0 ){
* Min = I;
Found = 1;
}
}
}
}
}
// Locate the top of the text containing the license plate and exclude the positions of the two screws
Void findy (iplimage * IMG, int * min, int * max)
{
Int found = 0;
Cvscalar maxval = cvrealscalar (IMG-> height * 255 );
Cvscalar val = cvrealscalar (0 );
Cvmat data;
Int mincount = IMG-> width * 255/5;
Int COUNT = 0;
For (INT I = 0; I height; I ++ ){
Cvgetrow (IMG, & Data, I );
Val = cvsum (& data );
If (Val. Val [0] <maxval. Val [0]) {
Count = Val. Val [0];
If (count> mincount & count height * 255 ){
* Max = I;
If (found = 0 ){
* Min = I;
Found = 1;
}
}
}
}
}
// Minimum area of the license plate character
Cvrect findarea (iplimage * IMG)
{
Int Minx, Maxx;
Int miny, Maxy;
Findx (IMG, & Minx, & Maxx );
Findy (IMG, & miny, & Maxy );
Cvrect rc = cvrect (Minx, miny, Maxx-Minx, Maxy-miny );
Return RC;
}
Int main (INT argc, char * argv [])
{
Iplimage * imgsrc = cvloadimage ("cp.jpg", cv_load_image_color );
Iplimage * img_gray = cvcreateimage (cvgetsize (imgsrc), ipl_depth_8u, 1 );
Cvcvtcolor (imgsrc, img_gray, cv_bgr2gray );
Cvthreshold (img_gray, img_gray, 100,255, cv_thresh_binary );
// Find the Minimum Region and capture
Cvrect rc = findarea (img_gray );
Cvsetimageroi (img_gray, RC );
Iplimage * img_gray2 = cvcreateimage (cvsize (RC. Width, RC. Height), ipl_depth_8u, 1 );
Cvcopyimage (img_gray, img_gray2 );
Cvresetimageroi (img_gray );
Iplimage * imgsrc2 = cvcreateimage (cvsize (RC. Width, RC. Height), ipl_depth_8u, 3 );
Cvsetimageroi (imgsrc, RC );
Cvcopyimage (imgsrc, imgsrc2 );
Cvresetimageroi (imgsrc );
// Morphology
Cvmorphologyex (img_gray2, img_gray2, null, null, cv_mop_close );
Cvseq * contours = NULL;
Cvmemstorage * storage = cvcreatememstorage (0 );
Int COUNT = cvfindcontours (img_gray2, storage, & contours,
Sizeof (cvcontour), cv_retr_external );
Int idx = 0;
Char szname [56] = {0 };
For (cvseq * c = s; C! = NULL; C = C-> h_next ){
// Cvdrawcontours (imgsrc2, C, cv_rgb (255, 0, 0), cv_rgb (255,255, 0), 100 );
Cvrect rc = cvboundingrect (C );
Cvdrawrect (imgsrc2, cvpoint (RC. x, RC. y), cvpoint (RC. X + RC. width, RC. Y + RC. (height), cv_rgb (255, 0, 0 ));
If (RC. width width/10 & rc. height height/5 ){
Continue;
}
Iplimage * imgno = cvcreateimage (cvsize (RC. Width, RC. Height), ipl_depth_8u, 3 );
Cvsetimageroi (imgsrc2, RC );
Cvcopyimage (imgsrc2, imgno );
Cvresetimageroi (imgsrc2 );
Sprintf (szname, "WND _ % d", idx ++ );
Cvnamedwindow (szname );
Cvshowimage (szname, imgno );
Cvreleaseimage (& imgno );
}
Cvnamedwindow ("src ");
Cvshowimage ("src", imgsrc2 );
Cvwaitkey (0 );
Cvreleasememstorage (& storage );
Cvreleaseimage (& imgsrc );
Cvreleaseimage (& imgsrc2 );
Cvreleaseimage (& img_gray );
Cvreleaseimage (& img_gray2 );
Cvdestroyallwindows ();
Return 0;
}
Input image:
The running result is as follows: