0

这段代码是 OpenCV c++:

lines = cvHoughCircles(frame2, storage, CV_HOUGH_GRADIENT, 1, 50, 300, 60, 10, 600);
for (int i = 0; i < lines.total(); i++) {
    //Would like the code to go here
     CvPoint2D32f point = new CvPoint2D32f(cvGetSeqElem(lines, i));
     cvCircle(src, cvPoint((int)point.x(), (int)point.y()), 3, CvScalar.WHITE, -1, 8, 0);
     Point p = new Point((int)point.x(), (int)point.y());
     points.add(p);
}

新的 Java Api 中的对应者是什么?我无法得到CvPoint2D32f,cvGetSeqElemCV_AA。我发现它存在于 JavaCV 但在 OpenCV Java api 中找不到它们。

谢谢

编辑:

我改变了我的代码,现在我有了:

MatOfPoint3 circles = new MatOfPoint3();
Imgproc.HoughCircles(image, circles, Imgproc.CV_HOUGH_GRADIENT,2, image.rows()/4,200,100,0,0);
for(Point3 circle : circles.toArray()){
     Point center = new Point(circle.x, circle.y);
     int radius = (int) Math.round(circle.z);      
     Core.circle(image, center, radius, new Scalar(0,255,0), 6, 8, 0);    
}

但是我在for(Point3 circle : circles.toArray())

Exception in thread "main" java.lang.UnsupportedOperationException: Mat data type is not compatible: 21
     at org.opencv.core.Mat.get(Mat.java:2581)
     at org.opencv.core.MatOfPoint3.toArray(MatOfPoint3.java:64)
     at org.opencv.core.MatOfPoint3.toList(MatOfPoint3.java:76)
     at main.java.DetectFaceDemo.run(HelloOpenCV.java:60)
at main.java.HelloOpenCV.main(HelloOpenCV.java:83)

对此有什么想法吗?谢谢

编辑2:

最后编辑问题的解决方案在于 MatOfPoint3 circles = new MatOfPoint3();

一定是 MatOfPoint3f circles = new MatOfPoint3f();

4

1 回答 1

1

使用类 Point3。由其坐标 x、y 和 z 指定的 3D 点的模板类。该类的一个实例可以与 C 结构 CvPoint2D32f 互换。与 Point_ 类似,可以将 3D 点的坐标转换为另一种类型。还支持向量算术和比较操作。

于 2013-10-22T10:47:50.160 回答