当前位置:首页 > 通信资讯 > 正文

opencv霍夫圆检测原理(opencv霍夫变换检测圆)

本程序是一个最简单的霍夫圆检测函数的使用案例,刚刚学会的用法,发一下,可以参考,参数啥的可根据图片调节。

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 #pragma once #include<quickopencv.h> #include<vector> #include <stdio.h> #include <iostream> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include<opencv2/opencv.hpp> using namespace cv; using namespace std; class QuickDemo { public: void ColorSpace_Demo(Mat &image); }; void QuickDemo::ColorSpace_Demo(Mat &image) { Mat gray, hsv, img3; cvtColor(image, gray, COLOR_BGR2GRAY); cvtColor(image, hsv, COLOR_BGR2HSV); //H取值0-180表示颜色 S取值0-255表示饱和度 V0-255表示亮度 namedWindow("huidu", WINDOW_FREERATIO); imshow("huidu", gray); GaussianBlur(gray, gray, Size(9, 9), 0, 0);//高斯模糊 medianBlur(gray, gray, 3);//中值滤波 vector<Vec3f> circles; HoughCircles(gray, circles, HOUGH_GRADIENT, 1, 1, 100,100, 0,00 ); Canny(gray, img3, 50, 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]); // circle center circle(gray, center, 3, Scalar(60, 30, 60), -1, 5, 0); // circle outline circle(gray, center, radius, Scalar(0, 60, 60), 3, 3, 0); } namedWindow("Hough Circle Transform Demo", WINDOW_FREERATIO); imshow("Hough Circle Transform Demo",gray); }

主函数调用

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 int main(int, char **argv) { Mat src = imread("D:/YUAN.jpg");//只能读八位或者小数图像,通道顺序B G R 取值空间为0-255 if (src.empty()) { cout<<"cant read"; return -1; } QuickDemo qd; qd.ColorSpace_Demo(src); waitKey(0); destroyAllWindows; return 0; }

运行效果如下

opencv霍夫圆检测原理(opencv霍夫变换检测圆)

到此这篇关于C++ opencv霍夫圆检测使用案例详解的文章就介绍到这了,更多相关C++ opencv霍夫圆检测使用内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/weixin_54598791/article/details/120247390

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。