我目前有一个可以使用openCV检测彩球的程序,我想添加HoughCircle方法以使其变得更好。
我本来是想对从[[inRange方法获得的阈值图像应用HoughCircle方法,但不幸的是它不起作用。我看到HoughCircle方法仅拍摄灰度图像,有没有办法将阈值图像传递给它?
这是我的工作方式:int isBall(Mat threshold){
Mat temp;
threshold.copyTo(temp);
std::vector<Vec3f> circles;
HoughCircles(temp, circles, CV_HOUGH_GRADIENT, 1, temp.rows/8
, 100
, 50
, 15 /* min radius */
, 200 /* max radius */
);
printf("nb circles = %d\n", circles.size());
if(circles.size() > 0){
return 1;
}
return 0;
}
阈值图像来自:inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
[这是我可以获得的阈值图像的示例:https://www.noelshack.com/2019-39-5-1569586501-threshold.png感谢您的帮助。
主要元凶是param2=50
,即threshold for circle centers at detection stage。如果将其设置为较小的值,该算法将能够返回圆。
我已经使用HoughCircles()
测试了param2=10
,结果是这样的: