LINUX opencv霍夫变换圆

LINUX opencv hough transform circle

我正在使用来自 the page. It works on most of my images. But it is failing on the attached image - the code fails to recognize outer dial/boundary of the gauge (in my original image, there is not inner white circle)

的代码

知道可能出了什么问题吗?

这就是你想要的吗...

如果是这样,那就是调整一些参数的问题。特别是最小和最大圆半径以及 circle_distance(检测到的圆之间的最小距离)。

要点here.

更新
如果你想将最小半径与图像尺寸相关联,你可以这样做:

float minRadius = MIN(img.size().width, img.size().height) * 0.5;

并将其提供给 houghCircles 函数。

我实际使用的参数(根据要点):

 HoughCircles(     img
                 , circles
                 , CV_HOUGH_GRADIENT //method – Detection method to use. 
                 // Currently,  the only implemented method is 
                 // CV_HOUGH_GRADIENT , which is  basically 21HT , 
                 // described in [Yuen90].
                 , 1 //p – Inverse ratio of the accumulator resolution to the 
                 // image resolution. For example, if dp=1 , the accumulator has 
                 // the same resolution as the input image. If dp=2 , 
                 // the accumulator has half as big width and height.
                 , 60  //minDist – Minimum distance between the centers of the 
                 // detected circles. If the parameter is too small, multiple 
                 // neighbor circles may be falsely detected in addition to a 
                 // true one. If it is too large, some circles may be missed.
                 , 100 //cannyThreshold – The higher threshold of the two 
                 // passed  to the gpu::Canny() edge detector 
                 // (the lower one is twice smaller).
                 , 30 //votesThreshold – The accumulator threshold for the circle 
                 // centers at the detection stage. The smaller it is, the more 
                 // false circles may be detected.
                 , 250 //minRadius – Minimum circle radius.
                 , 300 //maxRadius – Maximum circle radius.
                 );

评论已从 openCV documentation 移除。