OPENCV Learning License Plate Extraction

Source: Internet
Author: User

License plate recognition is divided into two steps, one is the license plate extraction, but character recognition.

Here is the license plate extraction.

VS2010.

OpenCV249.

Load Image char * path = "D:\\picture\\06.jpg"; Iplimage * frame = cvloadimage (path), if (!frame) return 0;cvnamedwindow ("frame" , 1); Cvshowimage ("Frame", frame);

Mean filter Cvsmooth (frame, frame, Cv_median),//cvsmooth (frame, frame, Cv_gaussian, 3, 3);//Grayscale Map iplimage * Gray = Cvcreateimage (Cvgetsize (frame), frame->depth, 1), Cvcvtcolor (frame, gray, Cv_bgr2gray), Cvnamedwindow ("Gray", 1); Cvshowimage (" Gray ", gray);
Edge detection Iplimage * temp = Cvcreateimage (Cvgetsize (Gray), ipl_depth_16s,1),//x direction gradient, vertical edge Cvsobel (Gray, temp, 2, 0, 3); I Plimage * Sobel = cvcreateimage (cvgetsize (temp), ipl_depth_8u,1), Cvconvertscale (temp, Sobel, 1, 0); Cvnamedwindow (" Sobel ", 1); Cvshowimage (" Sobel ", Sobel);

Binary Iplimage * threshold = Cvcreateimage (Cvgetsize (Sobel), gray->depth, 1); Cvthreshold (Sobel, threshold, 0, 255, cv_ thresh_binary| Cv_thresh_otsu); Cvnamedwindow ("threshold", 1); Cvshowimage ("threshold", threshold);

Morphological Changes Iplconvkernel * kernal;iplimage * morph = cvcreateimage (cvgetsize (Threshold), threshold->depth, 1);//Custom 1x3 The nucleus of the X-directional swelling corrosion kernal = Cvcreatestructuringelementex (3, 1, 1, 0, cv_shape_rect); Cvdilate (threshold, Morph, kernal, 2); 
   
    //x Expansion Unicom Digital Cverode (morph, Morph, kernal, 4);    x corrosion Removal of fragments cvdilate (morph, Morph, kernal, 4);   X expansion Recovery form//Custom 3x1 core for Y-direction expansion corrosion kernal = Cvcreatestructuringelementex (1, 3, 0, 1, cv_shape_rect); Cverode (morph, Morph, K Ernal, 1);    Y corrosion Removal fragments cvdilate (morph, Morph, kernal, 3);   Y Expansion Recovery morphology cvnamedwindow ("erode", 1), Cvshowimage ("Erode", morph);
   


Contour Detection Iplimage * Frame_draw = Cvcreateimage (Cvgetsize (frame), frame->depth, Frame->nchannels), cvcopy (frame, Frame_draw);  Cvmemstorage * storage = cvcreatememstorage (0);   CVSEQ * Contour = 0;   int count = cvfindcontours (morph, storage, &contour, sizeof (Cvcontour), Cv_retr_ccomp, cv_chain_approx_simple);   CVSEQ * _contour = contour;   for (; Contour! = 0; contour = contour->h_next) {Double Tmparea = fabs (Cvcontourarea (contour)); Cvrect arect = cvboundingrect (contour, 0);  if (Tmparea > (frame->height*frame->width)/10) {cvseqremove (contour,0);//Remove an area less than the set value of the contour, 1/10 continue;  } if (Arect.width < (arect.height*2)) {cvseqremove (contour,0);//Remove contour continue with a width-to-height ratio less than the set value;  }if ((Arect.width/arect.height) > 4) {cvseqremove (contour,0);//Remove contour continue with a width-to-height ratio less than the set value; }if ((Arect.height * arect.width) < ((Frame->height * frame->width)/100)) {cvseqremove (contour,0);//  Remove contour continue with a wide height ratio less than the set value; }cvscalar color = Cv_rgb (255, 0, 0); CvdrawcontouRS (frame_draw, contour, color, color, 0, 1, 8);//Draw external and internal contour}cvnamedwindow ("contour", 1); Cvshowimage ("Contour", Frame_draw); 


Here is the character segmentation and recognition.




OPENCV Learning License Plate Extraction

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.