【问题标题】:How to pass and use the parameters of JavaCV HoughCircles method如何传递和使用 JavaCV HoughCircles 方法的参数
【发布时间】:2015-10-20 07:57:47
【问题描述】:

我正在尝试使用 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 Mat 并以某种方式在控制台上打印圆的中心和半径。到目前为止我的尝试都失败了:我一直在尝试使用FloatBufferIndexer 迭代detectedCircles,这可能是正确的方向,但我还没有成功,有人可以帮忙吗?

请注意以下几点:

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

【问题讨论】:

    标签: java javacv mat hough-transform


    【解决方案1】:

    我只能使用 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);      
        }
    
    }
    

    尽管这并不能直接解决您的问题,但我希望这可能会有所帮助。

    【讨论】:

    • 感谢@Tzeencth,这确实可以解决我的问题,即使很难,我也希望看到使用 HoughCircle 方法,而不是 cvHoughCircles。在将此标记为我的问题的答案之前,我将等待一段时间。
    猜你喜欢
    • 2017-09-15
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多