EmguCV C#:FindContours()以检测不同的形状

问题描述 投票:0回答:1

我有这张图片:

enter image description here

我试图做的是检测它的轮廓。因此,通过查看文档和网络上的一些代码,我做到了这一点:

Image<Gray, byte> image = receivedImage.Convert<Gray, byte>().ThresholdBinary(new Gray(80), new Gray(255));
        Emgu.CV.Util.VectorOfVectorOfPoint contours = new Emgu.CV.Util.VectorOfVectorOfPoint();
        Mat hier = new Mat();

        CvInvoke.FindContours(image, contours, hier, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

        CvInvoke.DrawContours(receivedImage, contours, 0, new MCvScalar(255, 0, 0), 2);

然后它以蓝色检测到该轮廓:

enter image description here

现在,我想检测两个轮廓不同的矩形。因此结果将是这样的:

enter image description here

((用油漆制成)所以现在我想分别检测两个矩形(蓝色和红色矩形将是两个不同的轮廓)。但是我不知道该怎么做!

谢谢您的帮助! ;)

c# emgucv detection contour
1个回答
0
投票
问题来自ThresholdBinary的过程。正如我所了解的那样,此方法将返回一个二进制图像,由此,高于或等于threshold参数的所有像素都将上拉至maxValue参数,而将所有下面的像素均下拉至0。生成的图像因此将仅由0maxValue两个值组成。如果我们按照您的示例提供一些

假定

© www.soinside.com 2019 - 2024. All rights reserved.