图片缩小输出及边缘检测

#include<opencv2\opencv.hpp>
#include<cv.h>
#include<highgui.h>
#include<cxcore.h>

using namespace cv;


IplImage *doPryImage(IplImage * in, int filter = CV_GAUSSIAN_5x5) {          //图片一半显示
assert(in->width % 2 == 0 && in->height % 2 == 0);
IplImage * out = cvCreateImage(cvSize(in->width / 2, in->height / 2), in->depth, in->nChannels);
cvPyrDown(in, out);
return(out);

}


IplImage *doCanny(IplImage *in, double lowThresh, double highThresh, double aperture) {    //边缘检测
IplImage *out = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);     
if (in->nChannels != 1) {                      //当通道不为1时处理转换为单通道图片
IplImage * img = cvCreateImage(cvGetSize(in), in->depth, 1);
cvCvtColor(in, img, CV_RGB2GRAY);
cvCanny(img, out, lowThresh, highThresh, aperture);
return out;
}
cvCanny(in, out, lowThresh, highThresh, aperture);
return out;

}


int main( ) {


IplImage *img = cvLoadImage("D:\\ͼƬ\\2.jpg");
cvNamedWindow("picture_in");
cvNamedWindow("picture_out");

cvShowImage("picture_in", img);


IplImage * img_new = doPryImage(img,CV_GAUSSIAN_5x5);
cvShowImage("picture_out", img_new);
IplImage * img_two = doCanny(img, 10, 100,3);        
img_two = doPryImage(img_two, CV_GAUSSIAN_5x5);     //把转换后的边界图缩小输出
cvNamedWindow("canny_show");

cvShowImage("canny_show", img_two);


cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&img_new);
cvReleaseImage(&img_two);
cvDestroyAllWindows;
return 0;

}

运行结果:

图片缩小输出及边缘检测_第1张图片

你可能感兴趣的:(图片缩小输出及边缘检测)