【问题标题】:Equivalent of OpenCV statement in Java using JavaCV使用 JavaCV 的 Java 中 OpenCV 语句的等价物
【发布时间】:2012-02-19 09:25:37
【问题描述】:

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

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

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

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 opencv javacv


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 2014-06-01
      相关资源
      最近更新 更多