相关知识
相关程序
```cpp
#include "stdafx.h"
//本节讲述 图像处理之 canny边缘检测;
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace std;
using namespace cv;
Mat src, dst, dst1, dst2, dst3, dst4, dst6, dst5, gray_src;
int threshold_value = 50;
int threshold_max = 255;
void Canny_Demo(int,void*);
const char*output_title = "canny双阈值处理";
char input_title[] = "原图";
int main(int argc, char**argv)
{
src = imread("C:/Users/Rubison.DELL/Desktop\\杂物/壁纸/小白2.jpg"); //存放自己图像的路径
if (!src.data)
{
printf("could not load image...\r\n");
return -1;
}
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
//GaussianBlur(src, dst1, Size(3, 3), 0, 0);
cvtColor(src, gray_src, CV_BGR2GRAY);
Canny_Demo(0,0);
//Laplacian(gray_src, dst2, CV_16S, 3);
//convertScaleAbs(dst2, dst2);
//imshow("拉普拉斯算子", dst2); //噪点比较明显,因此进行阈值运算
//threshold(dst2, dst2, 0, 255, THRESH_OTSU | THRESH_BINARY);
createTrackbar("Threshold Value", output_title, &threshold_value, threshold_max, Canny_Demo);
/*imshow("拉普拉斯算子+自动阈值化", dst2);*/
waitKey(0);
destroyAllWindows();
return 0;
}
void Canny_Demo(int, void*)
{
blur(gray_src, gray_src, Size(3, 3), Point(-1, -1), BORDER_DEFAULT);
Canny(gray_src, dst4, threshold_value, threshold_value*2,3,false);
imshow("检测dst4", dst4);
dst5.create(src.size(), src.type()); //这两行代码是将原像素颜色拷贝到二值图中
//imshow("检测dst5", dst5);
src.copyTo(dst5, dst4); //从而生成彩色边缘图
imshow(output_title, dst5);
}
**运行结果**
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200927140321976.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3c1ODc1ODk1,size_16,color_FFFFFF,t_70#pic_center)
**备注:** 相关整理的很好的文章
1.[参考文章1](https://mp.weixin.qq.com/s?src=3×tamp=1601186133&ver=1&signature=z4eFpkoXsFvVXYvJtcTsr0F7JsxUdXnTLVa*-7Xy4hIhtTHM7ODkzrWArc01YGgM9doUAxLvOke1y8lwKKWYEz8dwo31CGClyn1HSeRa4sncTJA0U2XklYOz42MFDEB*KYg86yek1oFV6ZlxPQgUI-rqCHRxO2c6mG-G9UieNi4=)