Equivalent of OpenCV statement in Java using JavaCV

天涯浪子 提交于 2019-12-21 04:50:13

问题


I want to know how to construct the following C++ statement in OpenCV using JavaCV:

float* p = (float*)cvGetSeqElem(circles, i);
int radius = cvRound(p[2]);

To get the Radius of a circle detected using cvHoughCircles(). Obviously Java doesn't use pointer so I have no idea how to do this in Java. The code I have so far so you can see it context:

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);
}

回答1:


JavaCPP maps C/C++ arrays/pointers to Pointer objects, so we can access it in the same way as in C/C++, i.e.:

FloatPointer p = new FloatPointer(cvGetSeqElem(circles, i));
int radius = Math.round(p.get(2));


来源:https://stackoverflow.com/questions/9344503/equivalent-of-opencv-statement-in-java-using-javacv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!