函数作用
利用霍夫变换检测图像中的圆
函数原型
void cv::HoughCircles (InputArray image, // 8位单通道灰度图
OutputArray circles, // tyoe:vector<Vec3f>,(x,y,raduis)
int method, // 梯度求解方法:HOUGH_GRADIENT,HOUGH_GRADIENT_ALT
double dp, //累加器分辨率与图像分辨率的反比。
// 例如,如果dp=1,累加器的分辨率与输入图像相同。如果dp=2,则蓄能器的宽度和高度为原来的一半。
// 对于HOUGH_GRADIENT_ALT,建议值为dp=1.5,除非需要检测一些非常小的圆。
double minDist,// 检测到的圆中心之间的最小距离。
double param1 = 100,//Canny 检测的低阈值参数
double param2 = 100,//中心点累加器阈值,候选圆心
int minRadius = 0,// 最小圆半径
int maxRadius = 0 // 最大圆半径
)
Python:
cv.HoughCircles( image, method, dp, minDist[, circles[, param1[, param2[, minRadius[, maxRadius]]]]] ) -> circles
实例(来自opencv官网):
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <math.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat img, gray;
if( argc != 2 || !(img=imread(argv[1], 1)).data)
return -1;
cvtColor(img, gray, COLOR_BGR2GRAY);
// smooth it, otherwise a lot of false circles may be detected
GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
HoughCircles(gray, circles, HOUGH_GRADIENT,
2, gray.rows/4, 200, 100 );
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// draw the circle center
circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
// draw the circle outline
circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
namedWindow( "circles", 1 );
imshow( "circles", img );
waitKey(0);
return 0;
}
3万+

被折叠的 条评论
为什么被折叠?



