c# - Imgproc.FindContours 返回空轮廓

标签 c# android opencv xamarin

我将 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);
    }

Input Image

如果我用 FindContours 注释该行,我会得到一张用于搜索轮廓的极好的图片。

Threshholded image

FindContours 返回正确的图像(Reputation 不允许添加另一个链接),但是(!!)等高线列表为空。所以我无法获得这些结构的面积。 我很乐意提供任何帮助。谢谢!

最佳答案

使用 IList contours = new JavaList();

关于c# - Imgproc.FindContours 返回空轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37216096/

相关文章:

c# - 调用基类的方法

返回空 GraphUser 的 Android Facebook SDK v3.0 SSO LoginButton

python - Python内存使用情况-无法正确释放变量

c# - 静默刷新在 OPTIONS 预检上进行身份验证,但不在 GET 到 UserInfo 端点上进行身份验证

c# - 在 Blazor 中本地化日期时间(和数字)

c# - 当我显示它时,我的自定义 progressBar 表单挂起

android - VerticalGridFragment 无限滚动

ListView 的 ArrayList 上的 Android 空指针异常

python - 使用 OpenCV 和 Tkinter 在整个屏幕上显示视频

python - 从 python Opencv Videocapture 接收 Gazebo gstreamer UDP 视频