【发布时间】: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.Canny 和 Imgproc.GaussianBlur 那么结果是这样的(轮廓标记好)
否则,当我添加 Imgproc.FindContours 时,结果比不使用此方法最差(而且正如我所说,不会填充我的轮廓列表):
另一个图片来源#2:
没有 Imgproc.FindContours(仅 Imgproc.Canny 和 Imgproc.GaussianBlur):
使用 FindContours 方法:
不明白我的错误在哪里。有人可以为我解释一下,我在哪里做错了,或者我怎样才能实现我的目标?
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
如果你使用 JavaList
它对我有用,请参阅 stackoverflow.com/questions/40635635/… -
@Bjm 嗨,恭喜。正如我在回答中解释的那样,我已经以本机模式(Java)实现,然后绑定到我的 Xamarin 项目。无论如何,感谢您的评论和对 JavaList 的不良测试。
标签: android opencv xamarin transform perspective