// 第二章 课后练习题
// 题号:2.4
// 功能:读取摄像头的数据,将是视频文件的尺寸缩小一倍
// 将实时的图像显示出来。
#include "cv.h"
#include "highgui.h"
/*******************************************************************/
/* 函数名 : doPyrDown() 执行图形的向下图像金字塔
/* 参数 : input 输入图像
/* filter cvPyrDown()的默认参数
/* 功能 : 将输入图像input缩小一倍,并返回指向经过缩小处理图像的指针
/*******************************************************************/
IplImage *doPyrDown(IplImage *input,int filter=CV_GAUSSIAN_5x5)
{
//Make sure the width and the height of the image are divisable
assert(input->width%2==0 && input->height%2==0);
IplImage *output=cvCreateImage(cvSize(input->width/2,input->height/2),
input->depth,
input->nChannels);
assert(output!=NULL);
cvPyrDown(input,output,CV_GAUSSIAN_5x5);
return(output);
}
/**************************主函数**************************/
void main()
{
//create capture object
CvCapture *capture=cvCreateCameraCapture(0);
if (NULL==capture)
{
return ;
}
//create a window to show the image
cvNamedWindow("Show1");
cvNamedWindow("Show2");
//create a IplImage* object to receive image from capture
IplImage *image =cvQueryFrame(capture);
//To receive the image being pyrDowned
IplImage *change_iamge=cvCreateImage(cvSize(image->width/2,image->height/2),
image->depth,
image->nChannels);
while (NULL!=(image=cvQueryFrame(capture)))
{
change_iamge=doPyrDown(image);
cvConvertImage(change_iamge,change_iamge,CV_CVTIMG_FLIP);
//show the images in windows
cvShowImage("Show1",image);
cvShowImage("Show2",change_iamge);
//if press ESC break
char c=cvWaitKey(23);
if (27==c)
{
break;
}
}
//release the resourse
cvReleaseCapture(&capture);
cvDestroyWindow("Show1");
cvDestroyWindow("Show2");
}