簡體   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