霍夫圈检测精度非常低 [英] Hough circle detection accuracy very low

查看:123
本文介绍了霍夫圈检测精度非常低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从看起来非常清晰的图像中检测出圆形.我确实意识到圈子的一部分丢失了,但是从我读到的关于霍夫变换的内容看来,这似乎并不会导致我遇到的问题.

I am trying to detect a circular shape from an image which appears to have very good definition. I do realize that part of the circle is missing but from what I've read about the Hough transform it doesn't seem like that should cause the problem I'm experiencing.

输入:

输出:

代码:

// Read the image
Mat src = Highgui.imread("input.png");

// Convert it to gray
Mat src_gray = new Mat();
Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);

// Reduce the noise so we avoid false circle detection
//Imgproc.GaussianBlur( src_gray, src_gray, new Size(9, 9), 2, 2 );

Mat circles = new Mat();

/// Apply the Hough Transform to find the circles
Imgproc.HoughCircles(src_gray, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 1, 160, 25, 0, 0);

// Draw the circles detected
for( int i = 0; i < circles.cols(); i++ ) {
    double[] vCircle = circles.get(0, i);

    Point center = new Point(vCircle[0], vCircle[1]);
    int radius = (int) Math.round(vCircle[2]);

    // circle center
    Core.circle(src, center, 3, new Scalar(0, 255, 0), -1, 8, 0);
    // circle outline
    Core.circle(src, center, radius, new Scalar(0, 0, 255), 3, 8, 0);
}

// Save the visualized detection.
String filename = "output.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, src);

我把高斯模糊注释掉了,因为(直觉上是反计数),这大大增加了发现的同样不准确的圆的数量.

I have Gaussian blur commented out because (counter intuitively) it was greatly increasing the number of equally inaccurate circles found.

我的输入图像是否存在任何问题,会导致Hough无法正常工作?我的参数不正确吗?

Is there anything wrong with my input image that would cause Hough to not work as well as I expect? Are my parameters way off?

第一个答案提出了关于霍夫最小/最大半径提示的一个要点.我拒绝添加这些参数,因为本文中的示例图像只是半径从20到几乎无限变化的数千幅图像之一.

first answer brought up a good point about the min/max radius hint for Hough. I resisted adding those parameters as the example image in this post is just one of thousands of images all with varying radii from ~20 to almost infinity.

推荐答案

如果正确设置minRadiusmaxRadius参数,将会给您带来良好的效果.

If you'd set minRadius and maxRadius paramaeters properly, it'd give you good results.

对于您的图片,我尝试了以下参数.

For your image, I tried following parameters.

method - CV_HOUGH_GRADIENT
minDist - 100
dp - 1
param1 - 80
param2 - 10
minRadius - 250
maxRadius - 300

我得到以下输出

  • 注意:我在C ++中尝试过.

这篇关于霍夫圈检测精度非常低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆