OpenCV FindContours finds no contours on android

半世苍凉 提交于 2019-12-10 13:16:42

问题


I'm trying to find contours of an image, using OpenCV on android build with Xamarin (details about versions below).

I cannot get the FindCountours function to return any contours (the list is empty), even when using a pseudo image like below. Another problem is that there is one contour in the hierachy object.

It works when run from Python on Windows.

Does anybody know what could be the cause?

       Mat aoiHsv = new Mat(new Size(80, 80), CvType.Cv8uc3);
        for (int i = 20; i < 40; i++)
        {
            for (int j = 20; j < 40; j++)
            {
                aoiHsv.Put(i,j, new byte[] {180, 255, 255});
            }
        }

        Mat mask = new Mat();

        OpenCV.Core.Core.InRange(aoiHsv, new Scalar(179, 255, 255), new Scalar(255, 255, 255), mask);

        // Find contours
        IList<MatOfPoint> contours = new List<MatOfPoint>();
        Mat hierachy = new Mat();
        Imgproc.FindContours(mask, contours, hierachy, Imgproc.RetrCcomp, Imgproc.ChainApproxNone);

Version info:

  • OpenCV-3.1.0
  • Android 5.1 API 22

Found a solution: The contours list must be a JavaList, ie.

IList<MatOfPoint> contours = new JavaList<MatOfPoint>();

来源:https://stackoverflow.com/questions/40635635/opencv-findcontours-finds-no-contours-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!