EMGU-WPF Learning using-rectangle recognition

Source: Internet
Author: User

Original: EMGU-WPF learning using-rectangle recognition

Environment: Win8 64-bit Vs2015

EMGU version: Emgucv-windesktop 3.2.0.2682

Example diagram Upper Flow: Image--grayscale--truncation thresholding-------------------------------

Grayscale Image<gray, byte> imggray = new Image<gray, byte> (imgsrc.size); Cvinvoke.cvtcolor (IMGSRC, Imggray, Colorconversion.bgr2gray);//Truncation Threshold Image<gray, byte> imgThresholdTrunc = new Image<gray, byte> (imggray.size); Cvinvoke.threshold (Imggray, Imgthresholdtrunc, 255, thresholdtype.trunc);//median blur Image<gray, byte> ImgMedian = Imgthresholdtrunc.smoothmedian (7); Using 5*5//Gaussian blur Image<gray, byte> Imggaussian = Imgmedian.smoothgaussian (5);//swell, eliminate clutter mat oMat2 = Cvinvoke.getstructuringelement (Emgu.CV.CvEnum.ElementShape.Rectangle, New System.Drawing.Size (5, 5), new System.Drawing.Point (0, 0)); Image<gray, byte> imgerode = new Image<gray, byte> (imggray.size); Cvinvoke.erode (Imggaussian, Imgerode, OMAT2, New System.Drawing.Point (0, 0), 4, Bordertype.default, new Mcvscalar (255, 0, 0, 255));//corrosion, eliminate the clutter point image<gray, byte> imgdilate = new Image<gray, byte> (imggray.size); Cvinvoke.dilate (Imgerode, Imgdilate, OMAT2, New System.Drawing.Point (0, 0), 4, Bordertype.default, new Mcvscalar (255, 0, 0, 255));//Otsu two value Image<gray, byte> Imgthresholdotsu = new I Mage<gray, byte> (imggray.size); Cvinvoke.threshold (imgdilate, Imgthresholdotsu, 0, 255, Thresholdtype.otsu);

Example diagram lower flow: Original image, grayscale--truncated thresholding---eliminate crack->ostu two, identify contours-> draw contours.

Grayscale Image<gray, byte> imggray = new Image<gray, byte> (imgsrc.size); Cvinvoke.cvtcolor (IMGSRC, Imggray, Colorconversion.bgr2gray);//Truncation Threshold Image<gray, byte> imgThresholdTrunc = new Image<gray, byte> (imggray.size); Cvinvoke.threshold (Imggray, Imgthresholdtrunc, 255, thresholdtype.trunc);//Remove crack mat OMAT1 = Cvinvoke.getstructuringelement (Emgu.CV.CvEnum.ElementShape.Rectangle, New System.Drawing.Size (6, 6), new System.Drawing.Point (0, 0)); Image<gray, byte> Imgmorphologyex = new Image<gray, byte> (imggray.size); Cvinvoke.morphologyex (Imgthresholdtrunc, Imgmorphologyex, Emgu.CV.CvEnum.MorphOp.Close, OMAT1, new System.Drawing.Point (0, 0), 1, Bordertype.default, new Mcvscalar (255, 0, 0, 255));//Otsu two value Image<gray, byte> img Thresholdotsu = new Image<gray, byte> (imggray.size); Cvinvoke.threshold (Imgmorphologyex, Imgthresholdotsu, 0, 255, Thresholdtype.otsu); list<rotatedrect> boxlist = new list<rotatedrect> (); A box is a rotated Rectanglevectorofvectorofpoint contours = new Vectorofvectorofpoint (); Cvinvoke.findcontours (Imgthresholdotsu, contours, null, retrtype.list, chainapproxmethod.chainapproxsimple); Image &LT;BGR, byte> imgresult = new IMAGE&LT;BGR, byte> (imggray.size); Cvinvoke.cvtcolor (Imgthresholdotsu, Imgresult, COLORCONVERSION.GRAY2BGR); Mcvscalar Oscaler = new Mcvscalar (+, 255, 255, 255); int count = contours. size;for (int i = 0; i < count; i++) {using (Vectorofpoint contour = contours[i]) using (Vectorofpoint Approxcont our = new Vectorofpoint ()) {CVINVOKE.APPROXPOLYDP (contour, Approxcontour, cvinvoke.arclength (contour, True) * 0        ., true);        Double Darea = Cvinvoke.contourarea (Approxcontour, false);            if (Darea > Imgthresholdotsu.rows * imgthresholdotsu.cols/3d) {if (approxcontour.size = = 4) {#region Determine if all the angles in the contour is within [+] degree bool I    Srectangle = true;            System.drawing.point[] pts = Approxcontour.toarray ();                linesegment2d[] edges = Emgu.CV.PointCollection.PolyLine (pts, true); for (int j = 0; J < edges. Length; J + +) {Double angle = Math.Abs (edges[(j + 1)% edges. Length].                    Getexteriorangledegree (Edges[j]));                        if (Angle < | | angle >) {isrectangle = false;                    Break }} #endregion if (isrectangle) cvinvoke.drawcontours (imgr            Esult, contours, I, oscaler, 3); }        }    }}

EMGU-WPF Learning using-rectangle recognition

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.