OpenCV学习(七)之写入AVI视频文件

示例代码:

#include "highgui.h"
#include "cv.h"

using namespace cv;

//write a avi video
int main(int argc,char** argv)
{
	CvCapture* capture = 0;
	capture = cvCreateFileCapture("test.avi");
	if(!capture)
	{
		return -1;
	}
	IplImage* bgr_frame = cvQueryFrame(capture);  //init the video read
	double fps = cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);  //frame rate
	CvSize size = cvSize((int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH),cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT));
	CvVideoWriter* writer = cvCreateVideoWriter("out.avi",CV_FOURCC('M','J','P','G'),fps,size);
	IplImage* logPolarFrame = cvCreateImage(size,IPL_DEPTH_8U,3);
	while((bgr_frame = cvQueryFrame(capture)) != NULL)
	{
		cvLogPolar(bgr_frame,logPolarFrame,
			cvPoint2D32f(bgr_frame->width/2,bgr_frame->height/2),
			80,
			CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS
			/*CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS | CV_WARP_INVERSE_MAP*/);
		cvWriteFrame(writer,logPolarFrame);
	}
	cvReleaseVideoWriter(&writer);
	cvReleaseImage(&logPolarFrame);
	cvReleaseCapture(&capture);
	return 0;
}

使用了CvSizeCvVideoWriter类,以及其中的函数cvSize、cvCreateVideoWriter、cvWriteFrame。在每帧图像的变换中使用了cvLogPolar极坐标变换函数。程序运行完毕后你会在工程目录下看见一个名为out.avi的视频文件。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Easiest way to install: Load the program group AviDemo.bpg, install the package AviPack.dpk(bpl), try the demos. Read the source of AviWriter_2.pas (in AviPack) to get help on what the procedures and properties do. **Current version: AviWriter_2 ver 1.0.0.4 Changes: Finally got On-the-fly compression working with still being able to add an audio-stream. Use property OnTheFlyCompression (default is true) Also, now more than one audio file can be added. For each wav-file a delay (ms) can be specified, which says when it'll start playing. Use method AddWaveFile. In 1.0.0.3 the delay got too short. Now it seems to work, due to really adding "silence" from the end of the previous audio file. Note: Some Codecs don't support On-the-fly compression. If OnTheFlyCompression is false, only one wave file can be added. **A list of codec-gotchas: (still unclear about the exact range of occurrance) IV50 Indeo Video 5: Both frame dimensions must be a factor of 4. DIVX DivX codec: Both frame dimensions must be a factor of 4. Gives a floating point error under certain circumstances. More and more likely that this occurs if the frames are too "different". If this happens, then there's an AV in Avifil32.dll, don't know how to prevent this. The codec compresses real movies nicely at frametimes <=60 ms, when changing the settings in its dialog box as follows: Bitrate (1st page): to >=1300 Max Keyframe interval (2nd page): to <=20. MRLE MS-RLE Use that one if you want to make avis which play transparently in a TAnimate. (Thanks Eddie Shipman) But it does not support on-the-fly compression. Whenever a codec fails to work, there's this dreaded error "A call to an operating system function failed" while writing a compressed file, or an unhandled exception. The only way to prevent it, that I see, is, to collect more peculiarities about the codecs and stop execution in case of certain combinations of settings. When queried about their capabilities, some of these guys seem to lie. Renate Schaaf renates@xmission.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值