这段代码到OpenCV Java的翻译是什么?

时间:2013-10-22 10:29:15

标签: java c++ c opencv

此代码为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的记者是什么?我无法获得CvPoint2D32fcvGetSeqElemCV_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();

1 个答案:

答案 0 :(得分:1)

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