图像边缘计算 canny算子

原理:

#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespace cv; using namespace std; Mat src, dst,dst2,gray_src; char* INPUT_WIN = "input image"; char* OUTPUT_WIN = "binary image"; int t1_value = 50; int max_value = 255; void Canny_Demo(int, void*) { Mat edge_output; //中值滤波 blur(gray_src, edge_output, Size(3, 3), Point(-1, -1), BORDER_DEFAULT); Canny(edge_output, edge_output, t1_value, t1_value * 2, 3, false); imshow(OUTPUT_WIN, edge_output); } int main() { src = imread(".//pic//kate.png"); namedWindow(INPUT_WIN, CV_WINDOW_AUTOSIZE); namedWindow(OUTPUT_WIN, CV_WINDOW_AUTOSIZE); imshow(INPUT_WIN, src); cvtColor(src, gray_src, CV_BGR2GRAY); createTrackbar("Threshold Value", OUTPUT_WIN, &t1_value, max_value, Canny_Demo); Canny_Demo(0, 0); waitKey(0); return 0; }
原文地址:https://www.cnblogs.com/xiaochi/p/12011005.html