视频读取与新建

来源:互联网 发布:淘宝无需物流怎么设置 编辑:程序博客网 时间:2024/05/20 05:58
#include"highgui.h"
#include"cv.h"
IplImage *doPyrDown(IplImage *in, int filter = IPL_GAUSSIAN_5x5){
assert(in->width % 2 == 0 && in->height % 2 == 0);
IplImage *out = cvCreateImage(cvSize(in->width / 2, in->height / 2),
in->depth,
in->nChannels);
cvPyrDown(in, out);
return out;
}
int main(int argc, char **argv){
CvCapture *capture = 0;
capture = cvCreateFileCapture("30.avi");//read the origion 
if (!capture)//if the video is empty,then end program
return -1;
//the following steps are to get properties of capture;
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)
);
//now begin create new video,you must named it;
CvVideoWriter *writer = cvCreateVideoWriter(
"try.avi",
CV_FOURCC('M', 'J', 'P','G'),
fps,
size
);
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);
cvWaitKey(0);
return (0);
}
0 0
原创粉丝点击