[学习OpenCV攻略][007][缩小图片]

cvPryDown(输入图片,输出图片)

根据输出图片的大小,把输入图片进行压缩

 

cvPryUp(输入图片,输出图片)

根据输出图片的大小,把输入图片进行放大

 

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

IplImage *doPyrUp(IplImage *in){
	//assert(in->width%2 == 0 && in->height%2 == 0);
	
	//IplImage *out = cvCreateImage(cvSize(in->width/2, in->height/2), in->depth, in->nChannels);
	IplImage *out = cvCreateImage(cvSize(in->width*2, in->height*2), in->depth, in->nChannels);
	
	//cvPyrDown(in, out);
	cvPyrUp(in, out);
	
	return out;
}

int main(int argc, char **argv){
	IplImage *img = cvLoadImage(argv[1]);
	//IplImage *img2 = cvCreateImage(cvSize(img->width/2, img->height/2), img->depth, img->nChannels);
	IplImage *img2 = cvCreateImage(cvSize(img->width*2, img->height*2), img->depth, img->nChannels);
	
	cvNamedWindow("hello1", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("hello2", CV_WINDOW_AUTOSIZE);
	cvShowImage("hello1", img);
	
	//img2 = doPyrDown(img);
	img2 = doPyrUp(img);
	
	cvShowImage("hello2", img2);
	
	cvWaitKey(0);
	
	cvReleaseImage(&img);
	cvReleaseImage(&img2);
	cvDestroyWindow("hello1");
	cvDestroyWindow("hello2");
	
	return 0;
}

 

posted @ 2015-10-28 21:37  盛夏夜  阅读(311)  评论(0编辑  收藏  举报