//实现图片的2次缩放后再进行candy边缘检测
//Author:SD
//Date:2015-9-27
#include "cv.h"
#include "highgui.h"
//图像的缩放处理
//cvPyrDown()函数进行图像长宽的缩放(1/2)
IplImage* doPyrDown(IplImage * in, int filter = IPL_GAUSSIAN_5x5){
assert( in->width%2==0 && in->height%2==0);//要求输入的图片的长、宽可以被2整除。。。。
IplImage * end =cvCreateImage(cvSize (in->width/2, in->height/2),in->depth, in->nChannels);//图像的宽、高,图像元素的位深度,每个元素(像素)通道号
cvPyrDown(in,end);
return (end);
};
//candy边缘检测
IplImage* doCanny(IplImage* in ,double lowThresh, double highThresh, double aperture){
if(in->nChannels !=1) return (0);
IplImage* out =cvCreateImage(cvGetSize(in),IPL_DEPTH_8U,1);//像素8位,通道1号
cvCanny(in,out,lowThresh,highThresh,aperture);
return (out);
};
//主函数
int main(int argc, char **argv){
//载入图片
IplImage* img=cvLoadImage("E:\\picture\\y.jpg",0);
//申明调用函数
IplImage* doPyrDown(IplImage * in, int filter = IPL_GAUSSIAN_5x5);//缩放
IplImage* doCanny(IplImage* in ,double lowThresh, double highThresh, double aperture);//边缘检测
//2次缩放处理
IplImage* img1 =doPyrDown(img,IPL_GAUSSIAN_5x5);
IplImage* img2 =doPyrDown(img1,IPL_GAUSSIAN_5x5);
//边缘检测
IplImage* docanny_img=doCanny(img2 ,10, 200, 3);
//创建输出窗口
cvNamedWindow("原始图片");
cvNamedWindow("一次缩放");
cvNamedWindow("二次缩放");
cvNamedWindow("边缘检测");
//显示图片
cvShowImage("原始图片",img);
cvShowImage("一次缩放",img1);
cvShowImage("二次缩放",img2);
cvShowImage("边缘检测",docanny_img);
//等待按键事件,0毫秒
cvWaitKey(0);
//释放空间
cvReleaseImage(&img);
cvDestroyWindow("原始图片");
cvDestroyWindow("一次缩放");
cvDestroyWindow("二次缩放");
cvDestroyWindow("边缘检测");
}