送上新鲜的热腾腾的程序:
#include <highgui.h>
#include <cv.h>
IplImage * doPryDown(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,CV_GAUSSIAN_5x5);//filter=7 目前只支持CV_GAUSSIAN_5x5
return (out);
}
int main()
{
cvNamedWindow("example-in");
cvNamedWindow("example-out");
IplImage * in= cvLoadImage("I:\\资料\\opencv相关资料\\OpenCV教程\\图像与视频\\airplane.png");
cvShowImage("example-in",in);
IplImage * out = doPryDown(in);
cvShowImage("example-out",out);
cvWaitKey(0);//key point
cvReleaseImage(&in);
cvReleaseImage(&out);
cvDestroyWindow("example-in");
cvDestroyWindow("example-out");
}
cvPyrDown
cvPyrDown为openCV中的一个函数。
功能:
函数cvPyrDown使用Gaussian金字塔分解对输入图像向下采样。对图像进行缩放处理。
格式:
void cvPyrDown(const CvArr*src,CvArr*dst,int filter=CV_GAUSSIAN_5x5);
参数:
src 输入图像。
dst 输出图像,其宽度和高度应是输入图像的一半。
filter 卷积滤波器类型,目前仅支持CV_GAUSSIAN_5x5。
如果是连续进行的缩放变换呢?
我们看下面的程序:
#include <highgui.h>
#include <cv.h>
IplImage * doCanny(IplImage * in,double lowThresh,double highThresh,double aperture)
{
if(in->nChannels !=1)
{
return 0;
}
IplImage *out =cvCreateImage(cvSize(cvGetSize(in).width,cvGetSize(in).height),IPL_DEPTH_8U,1);
cvCanny(in,out,lowThresh,highThresh,aperture);
return (out);
}
IplImage * doPryDown(IplImage * in,int filter=CV_GAUSSIAN_5x5)
{
//assert(in->width%2==0 && in->height%2==0);
int width =(int) in->width/2;
int height = (int) in->height/2;
IplImage * out=cvCreateImage(cvSize(width,height),in->depth,in->nChannels);
cvPyrDown(in,out,CV_GAUSSIAN_5x5);//filter=7 目前只支持CV_GAUSSIAN_5x5
return (out);
}
int main()
{
cvNamedWindow("example-in");
cvNamedWindow("example-out");
IplImage * in=cvLoadImage("I:\\资料\\opencv相关资料\\OpenCV教程\\图像与视频\\rice.png",0);
cvShowImage("example-in",in);
IplImage * out=NULL;
//做两次连续的缩放变换和边缘检测
out = doPryDown(in,CV_GAUSSIAN_5x5);
out = doPryDown(in,CV_GAUSSIAN_5x5);
out = doCanny(in,1.0,3.0,3);
cvShowImage("example-out",out);
cvWaitKey(0);//key point
cvReleaseImage(&in);
cvReleaseImage(&out);
cvDestroyWindow("example-in");
cvDestroyWindow("example-out");
}
原文链接:http://www.cnblogs.com/feng-fan/archive/2013/02/27/2935475.html