繁体   English   中英

EMGUCV findContours自己如何获得积分?

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

使用findContours方法,我最终可以勾勒出人物形象。

我的示例图片来自创建者AForge.Net的网站。 结合使用absdiff和findContours,我可以使用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;
            }
        }
    }

在此处输入图片说明

轮廓是向量的向量

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

暂无
暂无

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

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