【问题标题】:Imgproc.FindContours doesnt fill List<MatOfPoint> of Contours Opencv AndroidImgproc.FindContours 不填充 List<MatOfPoint> 的 Contours Opencv Android
【发布时间】:2016-12-09 17:08:54
【问题描述】:

我正在为 Android(Xamarin)使用 OpenCV 2.4.11。我正在尝试检测矩形对象(纸页)并制作 wrapPerspective,类似于 tutorial 但对于 Android,像这样的步骤:
Canny edge -> 最大轮廓 -> 最大矩形 -> 找角 -> 透视变化。

using (Bitmap _img = BitmapFactory.DecodeFile(App._file.Path))
            {
                if (_img != null)
                {
                    m = new Mat();
                    grayM = new Mat();

                    Utils.BitmapToMat(_img, m);
                    //apply filter
                    Imgproc.Canny(m, m, 100, 100,3,true);
                    //gaus Blur
                    Imgproc.GaussianBlur(m,m,new Org.Opencv.Core.Size(5,5),5);
                    //list for contours
                    List<MatOfPoint> Contours = new List<MatOfPoint>();
                    Mat hierarcy = new Mat();
                   //our method to find contours,via filling List(Contours)
                    Imgproc.FindContours(m , Contours, hierarcy, Imgproc.RetrList, Imgproc.ChainApproxSimple);

                    System.Console.WriteLine(Contours.Count + " Contours founded");
                   //Dont know why,but Contours list is always empty(no values)
                    if (Contours.Count != 0)
                    {
                        MatOfPoint temp = Contours[0];
                    }
}    

我被困在这里,因为我不明白为什么这个方法(Imgproc.FindContours)不能填满我的轮廓列表(总是空的)。

还有奇怪的故障:
这是源图像#1
如果我只使用这些方法 Imgproc.CannyImgproc.GaussianBlur 那么结果是这样的(轮廓标记好)

否则,当我添加 Imgproc.FindContours 时,结果比不使用此方法最差(而且正如我所说,不会填充我的轮廓列表):

另一个图片来源#2:

没有 Imgproc.FindContours(仅 Imgproc.CannyImgproc.GaussianBlur):

使用 FindContours 方法:

不明白我的错误在哪里。有人可以为我解释一下,我在哪里做错了,或者我怎样才能实现我的目标?
任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 如果你使用 JavaList 它对我有用,请参阅 stackoverflow.com/questions/40635635/…
  • @Bjm 嗨,恭喜。正如我在回答中解释的那样,我已经以本机模式(Java)实现,然后绑定到我的 Xamarin 项目。无论如何,感谢您的评论和对 JavaList 的不良测试。

标签: android opencv xamarin transform perspective


【解决方案1】:

花了太多时间,我的结论是BUG,因为这种方法移植不好(不知道为什么)。
您可以尝试重新安装新版本(例如 Opencv 3.0.0)或以本机模式(Java)实现,然后在您的 MonoProject 中绑定。 享受吧!

【讨论】:

  • 当你说它不能很好地移植时,你有没有在其他平台上用完全相同的图像尝试过这个?我对 findContours() 的经验是,它需要大量的预处理(温柔的爱和关怀)才能找到您期望的正确轮廓。我不得不做很多步骤,比如精明、模糊、稀释、腐蚀、二元阈值化、锐化等。有时甚至是 HSV 颜色处理才能找到能够产生正确轮廓的图像。我相信 findContours() 方法也有一些参数来调整它找到的东西。
  • @medloh 是的,我在本机平台上尝试了完全相同的图像,它工作正常。问题在于 C# 版本的端口错误:)。
【解决方案2】:

我遇到了同样的问题。我发现解决方案是使用 JavaList 作为轮廓列表。

参考:https://github.com/TrekDev/Xamarin.Android.OpenCV/issues/1

【讨论】:

    猜你喜欢
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2019-03-01
    • 2013-12-22
    相关资源
    最近更新 更多