using Emgu.CV; using Emgu.CV.Util; VectorOfPoint curve = new VectorOfPoint(new Point[] { new Point(0, 0), new Point(10, 10), new Point(20, 0), new Point(30, 50), new Point(40, 0), new Point(50, 10), new Point(60, 0), }); VectorOfPoint approxCurve = new VectorOfPoint(); CvInvoke.ApproxPolyDP(curve, approxCurve, 10, true); // approximation curve contains only 3 points
// Load the image Mat image = CvInvoke.Imread("image.jpg", ImreadModes.AnyColor); // Convert to grayscale Mat gray = new Mat(); CvInvoke.CvtColor(image, gray, ColorConversion.Bgr2Gray); // Threshold the image Mat thresh = new Mat(); CvInvoke.Threshold(gray, thresh, 127, 255, ThresholdType.Binary); // Find contours in the image VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint(); CvInvoke.FindContours(thresh, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple); // Simplify contours VectorOfVectorOfPoint approxContours = new VectorOfVectorOfPoint(); for (int i = 0; i < contours.Size; i++) { VectorOfPoint curve = contours[i]; VectorOfPoint approxCurve = new VectorOfPoint(); CvInvoke.ApproxPolyDP(curve, approxCurve, 10, true); approxContours.Push(approxCurve); } // Display simplified contours ImageIn this example, ApproxPolyDP is used to simplify the contours found in an image. The simplified contours are then drawn on the image, making it easier to see the shapes present in the image.resultImage = image.ToImage (); CvInvoke.DrawContours(resultImage, approxContours, -1, new MCvScalar(255, 0, 0), 2); ImageViewer.Show(resultImage, "Simplified Contours");