2015-11-15 46 views
1

使用findContours方法,我最终能够勾勒出人物形象。EMGUCV findContours如何获得积分本身?

我的样本图片来自创作者AForge.Net的网站。与findContours一起使用absdiff我可以使用CvInvoke.cvDrawContours将轮廓自己绘制到屏幕上。

但是,我想要的是访问正在用来绘制轮廓的点。

在参考下面的图片,我想要得到那些构成蓝色轮廓的点。必须有某种方式才能达到那些不?

这是相关代码:

Image<Gray, byte> grayImage = new Image<Gray, byte>(colorImage); 
    Image<Bgr, byte> color = new Image<Bgr, byte>(colorImage); 

    Image<Bgr, byte> whiteconverter = new Image<Bgr, byte>(blankImage); 

    grayImage = grayImage.ThresholdBinary(new Gray(60), new Gray(255)); 

    grayImage._Not(); 

    using (MemStorage storage = new MemStorage()) 
    { 
     //add points to listbox 
     using (var p2 = new Pen(Color.Yellow, 2)) 
     { 
      var grp = Graphics.FromImage(pictureBox3.Image); 

      for (Contour<Point> 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<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.015, storage); 
       CvInvoke.cvDrawContours(whiteconverter, contours, new MCvScalar(255), new MCvScalar(255), -1, 2, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, new Point(0, 0)); 

       pictureBox3.Image = whiteconverter.Bitmap; 
      } 
     } 
    } 

enter image description here

回答

1

的轮廓矢量

的矢量

在EMGU你只需要多一个循环:

将下面的代码找到轮廓,然后抓取各个点。

注:不要使用'CV_CHAIN_APPROX_SIMPLE'...你不会得到所有的点。如果您使用CvInvoke.cvDrawContours()调用,这很有用。

请务必使用'CV_CHAIN_APPROX_NONE'...至少这是我的经验告诉我的。

Image<Gray, byte> grayImage = new Image<Gray, byte>(colorImage); 
    Image<Bgr, byte> color = new Image<Bgr, byte>(colorImage); 

    Image<Bgr, byte> whiteconverter = new Image<Bgr, byte>(blankImage); 

    grayImage = grayImage.ThresholdBinary(new Gray(0), new Gray(255)); 

    grayImage._Not(); 

    using (MemStorage storage = new MemStorage()) 
    { 
     using (var p2 = new Pen(Color.Yellow, 2)) 
     { 
      var grp = Graphics.FromImage(blankImage); 

      for (Contour<Point> contours = grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, 
       Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage); contours != null; contours = contours.HNext) 
      { 

       foreach (var ctr in contours) 
       { 
        grp.DrawEllipse(p2, ctr.X, ctr.Y, 4, 4); 
       } 

       pictureBox3.Image = blankImage; 
      } 
     } 
    }