簡體   English   中英

為什么Opencv Findcontour在Emgu c#中的行為有所不同?

[英]Why is Opencv Findcontour behaving differently in Emgu c#?

嗨,在opencv c +方法中, Findcontours返回數組層次結構,並獲取孔的邊界,我可以獲取層次結構。 我如何在emgu cv中獲得這些邊界,請提供任何幫助? 我如何在Emgu CV中發現孔?

您可以使用以下代碼在Emgucv中獲得Contour層次結構。

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; 

有關更多參考,請使用此在線輔導員! 這是此代碼的輸出。 http://s18.postimg.org/511xwpm15/Forum_Contour.jpg

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM