Imgproc.FindContours返回空轮廓

问题描述:

我使用OpenCV 2.4.11 Xamarin.Android与OpenCvBinding。我试图找到图像中最大的颜色区域。Imgproc.FindContours返回空轮廓

static public Tuple<Bitmap,double> GetArea(Bitmap srcBitmap) 
    { 
     Mat mat = new Mat(); 
     Mat gray = new Mat(); 
     Mat mat2 = new Mat(); 
     double max = 0; 
     Mat Hierarchy = new Mat(); 
     List<MatOfPoint> contours = new List<MatOfPoint>(); 
     Utils.BitmapToMat(srcBitmap, mat); 

     Imgproc.CvtColor(mat, gray, Imgproc.ColorRgba2gray); 
     Imgproc.AdaptiveThreshold(gray, mat2, 255, Imgproc.AdaptiveThreshGaussianC, Imgproc.ThreshBinaryInv,1111,0);  
     Imgproc.FindContours(mat2, contours, Hierarchy, Imgproc.RetrTree, Imgproc.ChainApproxSimple); 

     foreach (MatOfPoint contour in contours) 
     {  // never goes here 
      if (max < Imgproc.ContourArea(contour)) max = Imgproc.ContourArea(contour); 
     } 
     Utils.MatToBitmap(mat2,srcBitmap); 

     return new Tuple<Bitmap, double>(srcBitmap,max); 
    } 

Input Image

如果我评论与FindContours行了,我会得到一个很好的图片搜索轮廓。

Threshholded image

FindContours返回正确的图像(信誉不允许添加其他链接),但是(!!)轮廓站在空的列表。所以我无法得到这些结构的区域。 我很乐意提供任何帮助。谢谢!

+0

[看起来不太好,但显示图片中的轮廓显示正确。](http://imgur.com/Mi0qIXw) – SomeShapa

+0

我无法测试它,但您的样式错误使用层级结构为大写。 – Murphy4

使用IList轮廓= new JavaList();

+0

你可以给这个pease添加一些补充吗? –