简体   繁体   English

EMGUCV findContours自己如何获得积分?

[英]EMGUCV findContours how to get the points themselves?

Using the findContours method I'm ultimately able to outline the human figure. 使用findContours方法,我最终可以勾勒出人物形象。

My sample pictures were used from the creator AForge.Net's website. 我的示例图片来自创建者AForge.Net的网站。 Using an absdiff along with findContours I'm able to use CvInvoke.cvDrawContours to actually draw the contours themselves to the screen. 结合使用absdiff和findContours,我可以使用CvInvoke.cvDrawContours将轮廓本身绘制到屏幕上。

What I would like, however, is access to the points that are being used to draw those contours. 但是,我想要的是访问用于绘制这些轮廓的点。

In reference to the image below I want to get those points making up the blue contours. 参考下面的图片,我想获得构成蓝色轮廓的那些点。 There has to be some way to get to those no? 必须有某种方法来达到那些否?

This is the relevant code: 这是相关代码:

    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;
            }
        }
    }

在此处输入图片说明

The contours are a Vector of Vectors 轮廓是向量的向量

In EMGU you just needed one more loop: 在EMGU中,您仅需要一个循环:

The following code will find the contours and then grab the individual points. 以下代码将找到轮廓,然后获取各个点。

NOTE: Do not use 'CV_CHAIN_APPROX_SIMPLE'...you will not get all of the points. 注意:请勿使用“ CV_CHAIN_APPROX_SIMPLE” ...您将无法获得所有积分。 This is useful if you're using the CvInvoke.cvDrawContours() call. 如果您使用CvInvoke.cvDrawContours()调用,这将很有用。

Make sure to use 'CV_CHAIN_APPROX_NONE'...at least that's what my experience tells me. 确保使用“ 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;
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM