Imgproc.FindContours 未填充 Contours Opencv 的列表<MatOfPoint> Android
Imgproc.FindContours doesnt fill List<MatOfPoint> of Contours Opencv Android
我正在为 Android(Xamarin) 使用 OpenCV 2.4.11。我正在尝试检测矩形对象(Paper sheet)并制作 wrapPerspective,smiliar 这个 tutorial 但对于 Android,像这样的步骤:
Canny edge -> Largest contour -> 最大矩形 -> find corners -> perspective change.
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.Canny 和 Imgproc.GaussianBlur 然后结果是这样的(轮廓标记好)
否则,当我添加 Imgproc.FindContours 时,结果比 w/o 这种方法更差(正如我所说,没有填满我的轮廓列表) :
另一个图片来源#2:
w/o Imgproc.FindContours(只有 Imgproc.Canny 和 Imgproc.GaussianBlur) :
使用 FindContours 方法:
不明白我的错误在哪里。有人可以为我解释一下我哪里做错了或者我怎样才能实现我的目标?
任何帮助将不胜感激,谢谢!
花了太多时间,我的结论是BUG,因为这个方法移植不好(不知道为什么)。
您可以尝试重新安装新版本(例如 Opencv 3.0.0)或以本机模式(Java)实施,然后绑定到您的 MonoProject。
享受!
我 运行 遇到了同样的问题。我发现解决方案是对轮廓列表使用 JavaList。
参考:https://github.com/TrekDev/Xamarin.Android.OpenCV/issues/1
我正在为 Android(Xamarin) 使用 OpenCV 2.4.11。我正在尝试检测矩形对象(Paper sheet)并制作 wrapPerspective,smiliar 这个 tutorial 但对于 Android,像这样的步骤:
Canny edge -> Largest contour -> 最大矩形 -> find corners -> perspective change.
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.Canny 和 Imgproc.GaussianBlur 然后结果是这样的(轮廓标记好)
否则,当我添加 Imgproc.FindContours 时,结果比 w/o 这种方法更差(正如我所说,没有填满我的轮廓列表) :
另一个图片来源#2:
w/o Imgproc.FindContours(只有 Imgproc.Canny 和 Imgproc.GaussianBlur) :
使用 FindContours 方法:
不明白我的错误在哪里。有人可以为我解释一下我哪里做错了或者我怎样才能实现我的目标?
任何帮助将不胜感激,谢谢!
花了太多时间,我的结论是BUG,因为这个方法移植不好(不知道为什么)。
您可以尝试重新安装新版本(例如 Opencv 3.0.0)或以本机模式(Java)实施,然后绑定到您的 MonoProject。
享受!
我 运行 遇到了同样的问题。我发现解决方案是对轮廓列表使用 JavaList。
参考:https://github.com/TrekDev/Xamarin.Android.OpenCV/issues/1