OpenCV官方文档学习记录(18)

霍夫圆变换:

 1 #include <opencv2\opencv.hpp>
 2 #include <iostream>
 3 #include <string>
 4 #include <vector>
 5
 6 #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
 7
 8 using namespace std;
 9 using namespace cv;
10
11 void showImg(const string &win_name, const Mat &img)
12 {
13     namedWindow(win_name, CV_WINDOW_AUTOSIZE);
14     imshow(win_name, img);
15 }
16
17 int main(void)
18 {
19     Mat src = imread("panzi.jpg");
20     if (src.empty())
21         return -1;
22     Mat dst;
23     cvtColor(src, dst, CV_BGR2GRAY);
24     showImg("dst", dst);
25     GaussianBlur(dst, dst, Size(9, 9), 2, 2);
26     vector<Vec3f> circles;
27     HoughCircles(dst, circles, CV_HOUGH_GRADIENT, 1, dst.rows / 8, 200, 100, 0, 0);
28     for (size_t i = 0; i < circles.size(); ++i)
29     {
30         Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
31         int radius = cvRound(circles[i][2]);
32         circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);//绘制圆心
33         circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);//绘制圆
34     }
35     showImg("after ciecle decete", src);
36     waitKey();
37     return 0;
38 }

检测结果:

可见左侧的盘子没有被检出,但是却不知道是怎么回事,可能左侧不是正圆

分割检测的结果:

右侧:

左侧:

,因为用肉眼无法分辨,所以上述结果不好确定。

以上。

时间: 2024-08-28 23:52:03

OpenCV官方文档学习记录(18)的相关文章

OpenCV官方文档学习记录(4)

基本图形的绘制,官方文档给了一个实例,绘制下面两幅图形,分别使用了圆,椭圆,矩形,多边形,线等构造. 主要是使我们了解到如何构建这些形状,以及如何使用两种数据类型Point和Scalar分别定义点和颜色: 先放图: 完整代码如下: 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5 #pragma comment( linker, "/subsystem:\

OpenCV官方文档学习记录(16)

Canny边缘检测 先不说函数作用,来代码: 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5 #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 6 7 using namespace std; 8 u

OpenCV官方文档学习记录(11)

制作自己的filter, 主要使用filter2D函数: 先上代码: 1 #include "opencv2/opencv.hpp" 2 #include<iostream> 3 #include<string> 4 5 using namespace std; 6 using namespace cv; 7 8 int main(void) 9 { 10 Mat src,dst; 11 12 Mat kernel; 13 Point anthor; 14 do

OpenCV官方文档学习记录(6)

离散傅里叶变换:DFT,文档p165 代码如下: 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5 #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 6 7 #define NUMBER 20 8 9

OpenCV官方文档学习记录(5)

随机数生成类:RNG以及文字渲染 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5 #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 6 7 #define NUMBER 20 8 9 using na

OpenCV官方文档学习记录(15)

laplace边缘检测方式 不同于sobel的一阶导数式边缘检测,laplace算子是将图像的横纵都考虑进来的一种检测,主要使用的是二阶偏导数进行离散变换: 因为laplace也是使用分析梯度的方式进行变换,所以实际上调用的是sobel的方法.在上一篇上有体现,就是在两个方向上分别使用sobel计算结果. 代码如下: 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5

OpenCV官方文档学习记录(1)

图像显示并转化为黑白输出到新文件 code: 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5 #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 6 7 using namespace std; 8 u

OpenCV官方文档学习记录(19)

重映射(remapping) 主要涉及函数 remap 因为重映射函数所做的就是通过相应的矩阵参数,将原图像对应的像素点按照参数表达式重新排列到目标矩阵,所以通过不同的算法的描写可以形成许多操作: 1.保持原样: 1 #include <opencv2\opencv.hpp> 2 #include <iostream> 3 #include <string> 4 5 #pragma comment( linker, "/subsystem:\"win

OpenCV官方文档学习记录(13)

sobel边缘检测(导数运算) 主要函数Sobel() 1 #include<opencv2/opencv.hpp> 2 #include<iostream> 3 #include<string> 4 5 using namespace std; 6 using namespace cv; 7 8 void showImg(const string &win_name,const Mat &img) 9 { 10 namedWindow(win_name