本文介绍了使用JavaCV在Java中使用OpenCV语句的等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用JavaCV在OpenCV中构造以下C ++语句:

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

使用cvHoughCircles()获取圆的半径。显然Java不使用指针,所以我不知道如何在Java中这样做。我到目前为止的代码,你可以看到它的上下文:

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


推荐答案

JavaCPP映射C / C ++数组/指向Pointer对象的指针,所以我们可以以与C / C ++相同的方式访问它,即:

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

这篇关于使用JavaCV在Java中使用OpenCV语句的等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 14:43