2014-07-23 64 views
0

在opencv轮廓检测中,我得到多个轮廓靠近彼此。在这个图像中,我必须从每组最近的轮廓中选择一个轮廓。 我怎样才能选择一个组的轮廓。 我知道关于扩张图像,已经完成,但它不适合我。
看到附加的图像有四个轮廓。我需要从他们中选择两个,每个组中有一个。 怎么能实现这一点。 select a contours from group of possibles 从候选轮廓列表中选择一个轮廓

+2

迭代所有轮廓并只选择在已选轮廓内没有中心的轮廓时如何? –

回答

0

如果您有源图片like this &您想查找董事会from the Image。你可以按照这个伪代码。你可以很容易地用C++实现它。 请注意,在这里我使用CV_RETR_EXTERNAL参数来检索最外层的轮廓。

Image<Bgr, byte> Img_Result_Bgr = Img_Source_Bgr.Clone(); 
Image<Gray, byte> Img_Org_Gray = Img_Source_Bgr.Convert<Gray, byte>(); 
Img_Org_Gray = Img_Org_Gray.ThresholdBinary(new Gray(250), new Gray(255)); 

#region Finding Contours 
using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation 
    for (Contour<Point> contours = Img_Org_Gray.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL, storage); contours != null; contours = contours.HNext) 
    { 
     Contour<Point> contours_Approximated = contours.ApproxPoly(contours.Perimeter * 0.005,storage); 
     if (contours.Area > 10) //only consider contours with area greater than 100 
     { 
      Img_Result_Bgr.Draw(contours_Approximated, new Bgr(Color.Red), 2); 
     } 
    } 
#endregion 
imageBox1.Image = Img_Result_Bgr; 
+0

谢谢,我会在几分钟内尝试......并回复..而我在两者之间应用@ Random-I-Am的上述方法。 – Vivek