如何传递和使用JavaCV HoughCircles方法的参数



我试图使用HoughCircles方法的JavaCV实现,但我有一些参数问题。下面是我的代码:

Mat currentImageGray = tgtFrag.getImage().clone();
Mat detectedCircles = new Mat();
HoughCircles(currentImageGray, detectedCircles, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows() / 4, 0 );
if (detectedCircles != null && !detectedCircles.empty()) {
    // TO DO:
    // Print the center and the raidus of the detected circles.
}

首先,检测结果(HoughCircles的第二段)以Mat (detectedCircles)的形式给出。

我想处理detectedCircles垫,并以某种方式在控制台上打印圆的中心和半径。到目前为止,我的尝试失败了:我一直在尝试使用FloatBufferIndexer迭代detectedCircles,可能是正确的方向,但我还没有成功,有人可以帮助吗?

请注意以下内容:

  • 我使用JavaCV,不是openCV。
  • 我使用JavaCV HoughCircles,而不是cvHoughCircles(使用cvHoughCircles的解决方案也可以)。
  • 我使用的是最新版本的JavaCV,即1.0(2015年7月)。

我只能够使用JavaCV cvHoughCircles方法,不知道如何使用HoughCircles方法。这是我对你的代码的改编。

// Get the source Mat.
Mat myImage = tgtFrag.getImage();
IplImage currentImageGray = new IplImage(myImage);
CvMemStorage mStorage = CvMemStorage.create();
CvSeq detectedCircles = cvHoughCircles(currentImageGray, mStorage, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows() / 4, 0);
if (detectedCircles != null && detectedCircles.total() > 0) {
    for (int i = 0; i < detectedCircles.total(); i++) {
        CvPoint3D32f curCircle = new CvPoint3D32f(cvGetSeqElem(detectedCircles, i));
        int curRadius = Math.round(curCircle.z());
        Point curCenter = new Point(Math.round(curCircle.x()), Math.round(curCircle.y()));
        System.out.println(curCenter);
        System.out.println(curRadius);      
    }
}

虽然这并不能直接解决你的问题,但我希望这能对你有所帮助。

相关内容

最新更新