【发布时间】:2014-07-26 23:08:19
【问题描述】:
我们对 openCV Java 开发有点陌生,遇到了一个问题。
我们正在尝试将this code 转换为适用于 Android 的 Java。
approxPolyDp 需要一个 MatOfPoint2f,其中我们有 'approx' 参数。但是,当我们需要在 if 语句中使用相同的变量时,就在 isContourConvex 之后,它需要一个 MatOfPoint。最初的原始代码是使用 ArrayList 大约。我们对此感到非常困惑,需要朝着正确的方向轻推以了解我们应该做什么。
// Find contours
java.util.ArrayList<java.util.ArrayList<Point>>();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(bw.clone(), contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
// java.util.ArrayList<Point> approx = new java.util.ArrayList<Point>();
MatOfPoint2f approx = new MatOfPoint2f();
Mat dst = img.clone();
for (int i = 0; i < contours.size(); i++)
{
// Approximate contour with accuracy proportional
// to the contour perimeter
MatOfPoint2f contoursMat2 = new MatOfPoint2f( contours.get(i));
Imgproc.approxPolyDP(contoursMat2, approx, Imgproc.arcLength(contoursMat2, true) * 0.02, true);
// Skip small or non-convex objects
if (Math.abs(Imgproc.contourArea(contours.get(i))) < 100 || !Imgproc.isContourConvex(approx))
continue;
【问题讨论】:
-
你解决了这个问题吗?我需要这个。请分享