[学习OpenCV攻略][008][Canny边缘检测]

cvGetSize(输入图片)

得到输入图片的大小

 

cvCanny(输入图片,输出图片,lowThresh,highThresh,aperture)

把输入图片按设定光圈值进行Canny边缘检测,然后输出到输出图片中

 

#include "cv.h"
#include "highgui.h"

IplImage *doCanny(IplImage *in, double lowThresh, double highThresh, double aperture){
	if(in->nChannels != 1){
		return NULL;
	}
	
	IplImage *out = cvCreateImage(cvGetSize(in), in->depth, 1);
	cvCanny(in, out, lowThresh, highThresh, aperture);
	
	return out;
}

int main(int argc, char **argv){
	IplImage *img_rgb = cvLoadImage(argv[1]);
	IplImage *img_gry = cvCreateImage(cvSize(img_rgb->width, img_rgb->height), img_rgb->depth, 1);
	
	cvCvtColor(img_rgb, img_gry, CV_BGR2GRAY);
	
	cvNamedWindow("gray", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("canny", CV_WINDOW_AUTOSIZE);
	
	cvShowImage("gray", img_gry);
	
	IplImage *img_cny = doCanny(img_gry, 10, 100, 3);
	cvShowImage("canny", img_cny);
	
	cvWaitKey(0);
	
	cvReleaseImage(&img_cny);
	cvReleaseImage(&img_gry);
	cvReleaseImage(&img_rgb);
	
	cvDestroyWindow("canny");
	cvDestroyWindow("gray");
	
	return 0;
}

 

posted @ 2015-10-29 15:07  盛夏夜  阅读(258)  评论(0编辑  收藏  举报