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);
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM