OpenCV (十五)边缘检测算法canny算法
API介绍:
#include<opencv2/opencv.hpp> #include<iostream> using namespace std; using namespace cv; Mat src, dst; int threshold_value = 38; int threshold_max = 255; void canny_demo(int, void*); int main(int argc, char** argv) { src = imread("D:/OpenCVprj/image/test3.jpg"); if (!src.data) { printf("Coluld not load image.....\n"); return -1; } imshow("src", src); namedWindow("dst", CV_WINDOW_AUTOSIZE); createTrackbar("threshold", "dst", &threshold_value, threshold_max, canny_demo); canny_demo(0, 0); waitKey(0); return 0; } void canny_demo(int, void*) { Mat src_gray, temp; cvtColor(src, src_gray, COLOR_BGR2GRAY); blur(src_gray, src_gray, Size(3, 3), Point(-1, -1)); Canny(src_gray, temp, threshold_value, threshold_value * 2, 3, true); dst.create(src.size(), src.type()); src.copyTo(dst, temp);//第一种:A.copyTo(B),表示将A矩阵复制到B中;第二种:A.copyTo(B, mask),表示得到一个附加掩膜mask的矩阵B。 imshow("dst", dst); }