为什么Opencv Findcontour在Emgu c#中表现不同?

为什么Opencv Findcontour在Emgu c#中表现不同?,c#,emgucv,C#,Emgucv,在opencv c+方法中,HiFindcontours返回数组层次结构,为了得到孔的边界,我可以得到层次结构。 如何在emgu简历中获得这些边界?请提供帮助? 如何在emgu cv中查找孔?您可以使用以下代码在Emgucv中获取轮廓层次 Image<Bgr, byte> Img_Result_Bgr = Img_Source_Bgr.Copy(); Image<Gray, byte> Img_Org_Gray = Img_Source_Bgr.Convert<Gr

在opencv c+方法中,Hi
Findcontours
返回数组层次结构,为了得到孔的边界,我可以得到层次结构。 如何在emgu简历中获得这些边界?请提供帮助?
如何在emgu cv中查找孔?

您可以使用以下代码在Emgucv中获取轮廓层次

Image<Bgr, byte> Img_Result_Bgr = Img_Source_Bgr.Copy();
Image<Gray, byte> Img_Org_Gray = Img_Source_Bgr.Convert<Gray, byte>();
Image<Gray, byte> Img_CannyEdge_Gray = new Image<Gray, byte>(Img_Source_Bgr.Width,Img_Source_Bgr.Height);

Img_CannyEdge_Gray = Img_Org_Gray.Canny(10, 50);
Img_Org_Gray.Dispose();

Random Rnd = new Random();

#region Finding Contours
using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation
    for (Contour<Point> contours = Img_CannyEdge_Gray.FindContours(); contours != null; contours = contours.HNext)
    {
        Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);//if you want to Approximate the contours into a polygon play with this function().

        if (contours.Area > 100) //only consider contours with area greater than 100
        {
            Img_Result_Bgr.Draw(contours, new Bgr(Rnd.Next(255),Rnd.Next(255),Rnd.Next(255)), 2);
        }
    }
#endregion
Img_CannyEdge_Gray.Dispose();

imageBox1.Image = Img_Result_Bgr; 
Image Img_Result_Bgr=Img_Source_Bgr.Copy();
Image Img_Org_Gray=Img_Source_Bgr.Convert();
图像Img_CannyEdge_Gray=新图像(Img_Source_Bgr.宽度、Img_Source_Bgr.高度);
Img_CannyEdge_Gray=Img_Org_Gray.Canny(10,50);
Img_Org_Gray.Dispose();
随机Rnd=新随机();
#区域查找等高线
使用(MemStorage storage=new MemStorage())//为轮廓近似分配存储
对于(等高线等高线=Img_CannyEdge_Gray.FindContours();等高线!=null;等高线=等高线.HNext)
{
Contour currentContour=contours.ApproxPoly(contours.Permiture*0.05,存储);//如果要将轮廓近似为多边形,请使用此函数()。
如果(Curror面积>100)/只考虑面积大于100的等高线
{
Img_结果图(等高线,新的Bgr(Rnd.Next(255),Rnd.Next(255),Rnd.Next(255)),2);
}
}
#端区
Img_CannyEdge_Gray.Dispose();
imageBox1.Image=Img\u结果\u Bgr;
如需进一步参考,请使用此 下面是这段代码的输出。

谢谢,但我想在图像中找到漏洞。此代码能帮我吗?这是我要查找内部孔的图像??使用阈值对图像进行二值化,并使用findContour()函数的不同参数来查找孔。