标签:最大值 int opencv loading stream ace pen mat include
将空域点转化为极坐标,圆的极坐标表示如下
x=Rcosθ+a
y=Rsinθ+b
令xy已知,ab未知,则可以在原来的圆边界上上生成同样半径的圆
这些圆的交点就是圆心,在极坐标中,圆心点的始终处于最大值就是霍夫曼检测的原理(圆心是相交最多次数的点)
代码演示
#include"pch.h" #include<iostream> #include<opencv2/opencv.hpp> using namespace std; using namespace cv; int main(int argc, char **argv) { Mat src, dst; src = imread("2.jpg"); if (!src.data) { printf("Error\n"); return -1; } char INPUT_TITLE[] = "input_image"; char OUTPUT_TITLE[] = "hough_circle_demo"; namedWindow(INPUT_TITLE, CV_WINDOW_AUTOSIZE); namedWindow(OUTPUT_TITLE, CV_WINDOW_AUTOSIZE); imshow(INPUT_TITLE, src); //中值滤波 Mat mlf_opt; medianBlur(src, mlf_opt, 3);//ksize取3 cvtColor(mlf_opt, mlf_opt, CV_BGR2GRAY); //霍夫圆检测 vector<Vec3f> pcircles;//可能的圆心 HoughCircles(mlf_opt, pcircles, CV_HOUGH_GRADIENT, 1, 10, 100, 35, 5, 50); cout << pcircles[1] << endl; src.copyTo(dst); for (size_t i = 0; i < pcircles.size(); ++i) { Vec3f cc = pcircles[i]; circle(dst, Point(cc[0], cc[1]), cc[2], Scalar(0, 0, 255), 2, LINE_AA); circle(dst, Point(cc[0], cc[1]), 1, Scalar(198, 20, 255), 2, LINE_AA); } imshow(OUTPUT_TITLE, dst); waitKey(0); return 0; }
函数带有以下自变量:
circle打印圆,第一个打印边界,第二个打印圆心(半径调小)
标签:最大值 int opencv loading stream ace pen mat include
原文地址:https://www.cnblogs.com/wangtianning1223/p/13258417.html