我们对openCV Java开发有点陌生,遇到了一个问题。
我们正在尝试将this code转换为适用于安卓的Java。
approxPolyDp需要一个MatOfPoint2f,其中我们有'approx‘参数。但是,当我们需要在isContourConvex的if语句中使用相同的变量时,它需要一个MatOfPoint。最初的代码是使用ArrayList来表示约x。我们对此感到非常困惑,需要在正确的方向上推动,以理解我们应该做什么。
// 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;发布于 2020-05-22 15:15:00
对于那些将来看到这篇文章的人,这里是我的代码的摘录
MatOfPoint2f contour2f = new MatOfPoint2f(finalContour.get(i).toArray());
double approxDistance = Imgproc.arcLength(contour2f, true)*0.01;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
centers[i] = new Point();
MatOfPoint points = new MatOfPoint(approxCurve.toArray());
//if the contour has an circularness shape to it
if (approxCurve.toArray().length >= 8 && approxCurve.toArray().length <= 18) {
//insert codes here
}https://stackoverflow.com/questions/24068959
复制相似问题