C # open CV EMGU CV positioning license plate IDEA and code

Source: Internet
Author: User

---restore content starts---

Nothing recently, the company leaders want us to understand the image processing, so learning the following! Because I am not very good at C + +, I can only try to write code in C #! However, there is little information about EMGU CV on the Internet, and many of them are in English, and they are not detailed. So slowly pondering. Wrote a C # positioning license plate code, but the effect is not very ideal. Reference the Code of C + + master!

The idea is 1. Grayscale, Vertical edge detection

2. Adaptive binary Processing

3. Morphology treatment (swelling and corrosion)

4. Contour Search and filtering

The code is as follows:

IMAGE&LT;BGR, byte> simage = img;//New IMAGE<BGR, byte> ("license-plate.jpg"); //image<bgr, byte> simage = Sizeimage. Resize (n., Emgu.CV.CvEnum.INTER.CV_INTER_NN);Image<gray, byte> grayimg =NewImage<gray, byte>(simage. Width, Simage.            Height); INTPTR GRAYIMG1= Cvinvoke.cvcreateimage (simage. Size, Emgu.CV.CvEnum.IPL_DEPTH. IPL_DEPTH_8U,1); //GrayscaleCvinvoke.cvcvtcolor (simage. PTR, GRAYIMG1, Emgu.CV.CvEnum.COLOR_CONVERSION.            Bgr2gray); //first create a 16-depth signed image areaIntPtr Sobel = Cvinvoke.cvcreateimage (simage. Size, Emgu.CV.CvEnum.IPL_DEPTH. Ipl_depth_16s,1); //Sobel operator detection in X-directionCvinvoke.cvsobel (GRAYIMG1, Sobel,2,0,3); INTPTR Temp= Cvinvoke.cvcreateimage (simage. Size, Emgu.CV.CvEnum.IPL_DEPTH. IPL_DEPTH_8U,1); Cvinvoke.cvconvertscale (Sobel, temp,0.00390625,0); ////int it = Computethresholdvalue (Grayimg.tobitmap ()); ////Two value processing////image<gray, byte>dest = Grayimg.thresholdbinary (new Gray (it), new Gray (255));Image<gray, byte> dest =NewImage<gray, byte>(simage. Width, Simage.            Height); //two value processingCvinvoke.cvthreshold (temp, dest,0,255, Emgu.CV.CvEnum.THRESH.CV_THRESH_OTSU); INTPTR Temp1= Cvinvoke.cvcreateimage (simage. Size, Emgu.CV.CvEnum.IPL_DEPTH. IPL_DEPTH_8U,1); Image<gray, byte> dest1 =NewImage<gray, byte>(simage. Width, Simage.            Height); Cvinvoke.cvcreatestructuringelementex (3,1,1,0, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.            Cv_shape_rect, TEMP1); Cvinvoke.cvdilate (dest, Dest1, Temp1,6); Cvinvoke.cverode (Dest1, Dest1, Temp1,7); Cvinvoke.cvdilate (Dest1, Dest1, Temp1,1); Cvinvoke.cvcreatestructuringelementex (1,3,0,1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.            Cv_shape_rect, TEMP1); Cvinvoke.cverode (Dest1, Dest1, Temp1,2); Cvinvoke.cvdilate (Dest1, Dest1, Temp1,2); INTPTR DST= Cvinvoke.cvcreateimage (simage. Size, Emgu.CV.CvEnum.IPL_DEPTH. IPL_DEPTH_8U,3);            Cvinvoke.cvzero (DST); //Dest.            Dilate (10); //Dest. Erode (5);            using(Memstorage Stor =NewMemstorage ()) {Contour<Point> contours =Dest1. Findcontours (Emgu.CV.CvEnum.CHAIN_APPROX_METHOD. Cv_chain_approx_simple, Emgu.CV.CvEnum.RETR_TYPE.                Cv_retr_ccomp, Stor);  for(; Contours! =NULL; contours =contours. Hnext) {Rectangle box=contours.                    Boundingrectangle; Image&LT;BGR, byte> test =Simage.                    Copyblank (); Test. SetValue (255.0); DoubleWhratio = (Double) box. Width/box.                    Height; intArea = (int) box. Width *box.                    Height; if(Area > +&& area<10000)                    {                        if((3.0< Whratio && Whratio <6.0) ) {test. Draw (Box,NewBGR (color.red),2); Simage. Draw (Box,NewBGR (color.red),2); Cvinvoke.cvrectangle (Simage,NewPoint (box. X, Box. Y),NewPoint (box. X + box. Width, Box. Y + box. Height),NewMcvscalar (255,0,0),1, Emgu.CV.CvEnum.LINE_TYPE. eight_connected,0); //Cvinvoke.cvnamedwindow ("DST"); //cvinvoke.cvshowimage ("DST", DST);Imagebox1.image =Simage; }                    }                }            }

There's still some details that haven't been dealt with.

C # open CV EMGU CV positioning license plate IDEA and code

Related Article

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.