天天看點

opencv Canny邊緣檢測檢測

#include <iostream>
#include <opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;

int threshVal = 0;
Mat srcImg;

void cannyCall(int)
{
	Mat dstImg, edgeImg;
	GaussianBlur(srcImg, dstImg, Size(3, 3), 0, 0, BORDER_DEFAULT);
	Canny(dstImg, edgeImg, double(threshVal), double(threshVal * 2), 3, false);
	imshow("Image", edgeImg);
}

int main ()
{
    srcImg = imread("Leno.jpg", IMREAD_GRAYSCALE);
	if (srcImg.empty())
	{
		cout << "Image load failed" << endl;
		return -1;
	}
	namedWindow("Image", WINDOW_AUTOSIZE);
	cvCreateTrackbar("Value", "Image", &threshVal, 100, cannyCall);
	cannyCall(0);
	waitKey(0);
	return 0;
}