在emgucv中查找轮廓点

我正在使用emguCV来查找轮廓基本点然后将此点保存在文件中,并且用户将来重新绘制此形状。 所以,我的目标是这个形象:


例

我的解决方案是:1。将图像导入到图片框2.使用canny算法进行边缘检测3.找到轮廓并保存点

我在下面的代码中找到了很多分数但是我不能用这一点绘制第一个形状!

using Emgu.CV; using Emgu.Util; private void button1_Click(object sender, EventArgs e) { Bitmap bmp = new Bitmap(pictureBox1.Image); Image img = new Image(bmp); Image gray = img.Convert().PyrDown().PyrUp(); Gray cannyThreshold = new Gray(80); Gray cannyThresholdLinking = new Gray(120); Gray circleAccumulatorThreshold = new Gray(120); Image cannyEdges = gray.Canny(cannyThreshold, cannyThresholdLinking).Not(); Bitmap color; Bitmap bgray; IdentifyContours(cannyEdges.Bitmap, 50, true, out bgray, out color); pictureBox1.Image = color; } public void IdentifyContours(Bitmap colorImage, int thresholdValue, bool invert, out Bitmap processedGray, out Bitmap processedColor) { Image grayImage = new Image(colorImage); Image color = new Image(colorImage); grayImage = grayImage.ThresholdBinary(new Gray(thresholdValue), new Gray(255)); if (invert) { grayImage._Not(); } using (MemStorage storage = new MemStorage()) { for (Contour contours = grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage); contours != null; contours = contours.HNext) { Contour currentContour = contours.ApproxPoly(contours.Perimeter * 0.015, storage); if (currentContour.BoundingRectangle.Width > 20) { CvInvoke.cvDrawContours(color, contours, new MCvScalar(255), new MCvScalar(255), -1, 1, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, new Point(0, 0)); color.Draw(currentContour.BoundingRectangle, new Bgr(0, 255, 0), 1); } Point[] pts = currentContour.ToArray(); foreach (Point p in pts) { //add points to listbox listBox1.Items.Add(p); } } } processedColor = color.ToBitmap(); processedGray = grayImage.ToBitmap(); } 

在您的代码中,您添加了轮廓近似操作

 Contour currentContour = contours.ApproxPoly(contours.Perimeter * 0.015, storage); 

此轮廓近似将近似于Contour到最近的多边形 ,因此实际点已移位。 如果要重现相同的图像,则无需进行任何近似。

请参阅此主题。