网上查了下,没能找到关于learning opencv的课后习题讲解,现张贴出自我学习过程的code,与广大Coder共同探讨学习,多多指出小弟的错误,谢谢。
题目:使用例2-10中的视频捕捉和存储方法,结合例2-5中的doPyrDown()创建一个程序,使其从摄像机读入视频数据并将缩放变换后的彩色图像存入磁盘。
/* 使用例2-10中的视频捕捉和存储方法,结合例2-5中的doPyrDown()创建一个程序, 使其从摄像机读入视频数据并将缩放变换后的彩色图像存入磁盘 chapter2-3 */ #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <cv.h> #include <iostream> using namespace std; using namespace cv; IplImage *doPyrDown(IplImage * in) { IplImage* out = cvCreateImage( cvSize(in->width/2,in->height/2), in->depth, in->nChannels ); //借用下opencv1 中的cvPyrDown函数修改frame尺寸 cvPyrDown(in,out,CV_GAUSSIAN_5x5); return out; } int main (int argc,char* argv[]) { CvCapture* capture = cvCreateFileCapture("D:\\123.avi"); if(!capture) { cout<<"Fail to open!"<<endl; return -1; } IplImage* bgr_frame = cvQueryFrame(capture); double fps = cvGetCaptureProperty(capture,CV_CAP_PROP_FPS); CvSize size = cvSize( (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH)/2, (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT)/2 ); CvVideoWriter *writer = cvCreateVideoWriter( "2.avi", CV_FOURCC('M','J','P','G'), fps, size ); IplImage * logpolar_frame = cvCreateImage( size, IPL_DEPTH_8U, 3 ); while( (bgr_frame = cvQueryFrame(capture)) != NULL ) { IplImage* out = doPyrDown(bgr_frame); cvWriteFrame(writer,out); } cvReleaseVideoWriter(&writer); cvReleaseImage(&logpolar_frame); cvReleaseCapture(&capture); return 0; }