OpenCV例子三:将文字生成视频文件

#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>  // OpenCV window I/O
using namespace cv;//必须加入,否则无法检找到OPENCV的各个函数
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

	Size s(320, 240);
	//VideoWriter wr("dd.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25, s);//无法使用该参数
	VideoWriter wr("dd.avi", -1, 25, s);

	if (!wr.isOpened())
	{
		cout << "open faild 2.." << endl;
		return -1;
	}

	char text[10] = { 0 };
	Mat fm(s, CV_8SC3);
	for (int i = 0; i < 100; i++)
	{
		fm = Scalar::all(255);
		sprintf_s(text, "%d", i);
		putText(fm, text, Point(s.width / 3, s.height / 3), FONT_HERSHEY_COMPLEX, 3, Scalar(0, 0, 255), 3, 8);
		wr << fm;
	}

	waitKey();
	return 0;
}

注意:

//VideoWriter wr("dd.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25, s);必须有编码器才支持。

因此使用VideoWriter wr("dd.avi", -1, 25, s);中,传入-1选择系统支持的编码器。

生成完毕后,就可以用播放器播放dd.avi文件。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值