#include "cv.h"
#include "highgui.h"
int main(int argc,char* argv[]){ //书本中的main没有定义为int返回类型,就会报错:c++默认不支持int
CvCapture* capture = 0;
capture = cvCreateFileCapture("p.avi");//p.avi直接存放在当前cpp文件所在的文件夹下,所有不用写路径,否则如:D:\sandy\visual studio 2010\Projects\video\video\p.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("d:\shengcheng.avi",CV_FOURCC('M','J','P','G'),fps,size);//把CV_FOURCC('M','J','P','G')改为-1,就在d盘生成一个shengcheng.avi文件了,我也没搞懂为什么
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);
cvWriteFrame(writer,logpolar_frame);
}
cvReleaseVideoWriter(&writer);
cvReleaseImage(&logpolar_frame);
cvReleaseCapture(&capture);
return(0);
}
原视频:
生成视频: