打开视频文件,对每一帧进行极坐标变换,然后将转换生成的图像序列写入视频文件中
#include "cv.h" #include "highgui.h" int main(int argc,char** argv) { CvCapture* capture=0; capture = cvCreateFileCapture("video.avi"); if(!capture) 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), (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT)); //CvVideoWriter* writer=cvCreateVideoWriter("ji.avi",CV_FOURCC('M','J','P','G'),fps,size); CvVideoWriter* writer=cvCreateVideoWriter("ji.avi",-1,fps,size); /* avi对应的编码格式分别为: CV_FOURCC('P','I','M','1') = MPEG-1 codec CV_FOURCC('M','J','P','G') = motion-jpeg codec (does not work well) CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec CV_FOURCC('U', '2', '6', '3') = H263 codec CV_FOURCC('I', '2', '6', '3') = H263I codec CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec */ IplImage* logpolar_frame=cvCreateImage(size,IPL_DEPTH_8U,3); while((bgr_frame=cvQueryFrame(capture))!=NULL) { cvLogPolar(bgr_frame,logpolar_frame,cvPoint2D32f(bgr_frame->width/2,bgr_frame->height/2),40,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS); /* src 源图像 dst 目标图像 center 变换中心,此处输出精度最高。 M 幅度尺度参数 flags:为插值方法标示与下面选项的组合: CV_WARP_FILL_OUTLIERS 填充目标图像中的所有像素,如果某些像素对应于源图像之我的位置,则用0填充. CV_WARP_INVERSE_MAP 表示矩阵是从目标图像到源图像的反变换,因此,可以直接用于像素插值;否则,函数从map_matrix寻找变换。 */ cvWriteFrame(writer,logpolar_frame); } cvReleaseVideoWriter(&writer); cvReleaseImage(&logpolar_frame); cvReleaseCapture(&capture); return 0; }
cvCreateVideoWriter :Under Win32 it is possible to pass -1 in order to choose compression method and additional compression parameters from dialog。
如果使用指定的编码不能成功写入,使用-1替换CV_FOURCC,运行时会有提示让你自己选择 codec 。