问题
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