Why is Opencv Findcontour behaving differently in Emgu c#?

旧巷老猫 提交于 2019-12-02 09:31:41

You can get the Contour hierarchy in Emgucv by using this following code.

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; 

For further Reference use this Online Tutor! Here is the output of this code. http://s18.postimg.org/511xwpm15/Forum_Contour.jpg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!