OpenCV基础课程笔记20canny边缘检测
程序员文章站
2023-12-23 15:44:22
...
写在前面
有助于理解非最大信号抑制博客
https://blog.csdn.net/qq_38906523/article/details/80195119?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allfirst_rank_v2~rank_v25-7-80195119.nonecase&utm_term=%E6%9C%80%E5%A4%A7%E6%8A%91%E5%88%B6%E7%AE%97%E6%B3%95
Canny算法处理边缘:
1 GaussianBlur
2 cvtColor
3 Sobel/Scharr
4 非最大信号抑制
5 高低阈值输出二值图像
代码
#include<iostream>
#include<opencv2/opencv.hpp>
#include<cmath>
using namespace std;
using namespace cv;
Mat gray_src, dst;
int t1_value = 40;
int max_value = 255;
Mat src = imread("A:\\专用\\TestForTheCV\\代替女友出境.jpg");
void Canny_Demo(int, void *);
char srcWin[] = "src";
int main() {
imshow(srcWin, src);
cvtColor(src, gray_src, CV_BGR2GRAY);
createTrackbar("Threshold value", srcWin, &t1_value, max_value, Canny_Demo);
Canny_Demo(0, 0);
waitKey(0);
return 0;
}
void Canny_Demo(int ,void*) {
Mat output;
blur(gray_src, gray_src, Size(3, 3), Point(-1, -1));
Canny(gray_src, output, t1_value, t1_value * 2, 3, false);
dst.create(src.size(), src.type());
src.copyTo(dst, output);
//imshow("彩色", dst);
//imshow("灰色",output);
imshow("灰色取反", ~output);
}
/*
有助于理解非最大信号抑制博客
https://blog.csdn.net/qq_38906523/article/details/80195119?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~first_rank_v2~rank_v25-7-80195119.nonecase&utm_term=%E6%9C%80%E5%A4%A7%E6%8A%91%E5%88%B6%E7%AE%97%E6%B3%95
Canny算法处理边缘:
1 GaussianBlur
2 cvtColor
3 Sobel/Scharr
4 非最大信号抑制
5 高低阈值输出二值图像
*/