我将 OpenCV 2.4.11 用于带有 OpenCvBinding 的 Xamarin.Android。我试图找到图像中最大的颜色区域。
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);
}
如果我用 FindContours 注释该行,我会得到一张用于搜索轮廓的极好的图片。
FindContours 返回正确的图像(Reputation 不允许添加另一个链接),但是(!!)等高线列表为空。所以我无法获得这些结构的面积。 我很乐意提供任何帮助。谢谢!
最佳答案
使用 IList contours = new JavaList();
关于c# - Imgproc.FindContours 返回空轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37216096/