视频稳像操作

#include <opencv2/opencv.hpp>
#include <opencv2/videostab.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace cv;
using namespace cv::videostab;

string inputPath = "optical_flow_input.avi";
string outputPath = "output.avi";

// 视频稳定输出
void videoOutput(Ptr<IFrameSource> stabFrames, string outputPath)
{
	VideoWriter writer;
	cv::Mat stabFrame;
	int nframes = 0;
	// 设置输出帧率
	double outputFps = 25;
	// 遍历搜索视频帧
	while (!(stabFrame = stabFrames->nextFrame()).empty())
	{
		nframes++;
		// 输出视频稳定帧
		if (!outputPath.empty())
		{
			if (!writer.isOpened())
				writer.open(outputPath, VideoWriter::fourcc('X', 'V', 'I', 'D'),
					outputFps, stabFrame.size());
			writer << stabFrame;
		}
		imshow("stabFrame", stabFrame);
		// esc键退出
		char key = static_cast<char>(waitKey(3));
		if (key == 27)
		{
			cout << endl;
			break;
		}
	}
	std::cout << "nFrames: " << nframes << endl;
	std::cout << "finished " << endl;
}
void cacStabVideo(Ptr<IFrameSource> stabFrames, string srcVideoFile)
{
	try
	{

		Ptr<VideoFileSource> srcVideo =
			makePtr<VideoFileSource>(inputPath);
		cout << "frame count: " << srcVideo->count() << endl;
		// 运动估计
		double estPara = 0.1;
		Ptr<MotionEstimatorRansacL2> est =
			makePtr<MotionEstimatorRansacL2>(MM_AFFINE);
		// Ransac参数设置
		RansacParams ransac = est->ransacParams();
		ransac.size = 3;
		ransac.thresh = 5;
		ransac.eps = 0.5;
		// Ransac计算
		est->setRansacParams(ransac);
		est->setMinInlierRatio(estPara);
		// Fast特征检测
		Ptr<FastFeatureDetector> feature_detector =
			FastFeatureDetector::create();
		// 运动估计关键点匹配
		Ptr<KeypointBasedMotionEstimator> motionEstBuilder =
			makePtr<KeypointBasedMotionEstimator>(est);
		// 设置特征检测器
		motionEstBuilder->setDetector(feature_detector);
		Ptr<IOutlierRejector> outlierRejector =
			makePtr<NullOutlierRejector>();
		motionEstBuilder->setOutlierRejector(outlierRejector);
		// 3-Prepare the stabilizer
		StabilizerBase *stabilizer = 0;
		// first, prepare the one or two pass stabilizer
		bool isTwoPass = 1;
		int radius_pass = 15;
		if (isTwoPass)
		{
			// with a two pass stabilizer
			bool est_trim = true;
			TwoPassStabilizer *twoPassStabilizer = new TwoPassStabilizer();
			twoPassStabilizer->setEstimateTrimRatio(est_trim);
			twoPassStabilizer->setMotionStabilizer(
				makePtr<GaussianMotionFilter>(radius_pass));
			stabilizer = twoPassStabilizer;
		}
		else
		{
			// with an one pass stabilizer
			OnePassStabilizer *onePassStabilizer = new OnePassStabilizer();
			onePassStabilizer->setMotionFilter(
				makePtr<GaussianMotionFilter>(radius_pass));
			stabilizer = onePassStabilizer;
		}
		// second, set up the parameters
		int radius = 15;
		double trim_ratio = 0.1;
		bool incl_constr = false;
		stabilizer->setFrameSource(srcVideo);
		stabilizer->setMotionEstimator(motionEstBuilder);
		stabilizer->setRadius(radius);
		stabilizer->setTrimRatio(trim_ratio);
		stabilizer->setCorrectionForInclusion(incl_constr);
		stabilizer->setBorderMode(BORDER_REPLICATE);
		// cast stabilizer to simple frame source interface to read stabilized frames
		stabFrames.reset(dynamic_cast<IFrameSource*>(stabilizer));
		// 4-videoOutput the stabilized frames. The results are showed and saved.
		videoOutput(stabFrames, outputPath);
	}
	catch (const exception &e)
	{
		cout << "error: " << e.what() << endl;
		stabFrames.release();
	}
}
int main()
{
	Ptr<IFrameSource> stabFrames;
	// 输入输出视频准备

	cacStabVideo(stabFrames, inputPath);
	stabFrames.release();
	return 0;
}



转载:http://blog.csdn.net/zhuwei1988

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
iSee视频监控 v5.2 视频监控软件使用说明书 版权所有 翻录必究 2009年10月1日 Ver:01.01.05 注意事项 首先,感谢您选用我公司最新产品。 在使用本监控卡之前,请详细阅读本说明书所涉及的相关事项,熟悉 硬件、软件各部分的功能后,方能使用,以确保该系统为您发挥最佳功能。 否则一切后果自负。 本说明书将向您详细阐述全实时“视频监控系统”的安装、操作、设 置和网络使用方法。 本系统工作主机供电电压为220V_10%,如果在电压不稳或者干扰大 的场合,请您选用优质稳压电源(即UPS),保证系统正常良好的工作状态。 本系统在安装、拆卸视频采集卡时,必须将主机处于完全断电状态, 否则主板上残留的电压将损坏采集卡。 本系统可切换D1与CIF分辨率,切换分辨率设置后,在主界面必须关 闭通道视频,重新打开通道视频,设置才能生效。 本系统主机工作于常温(-10_3℃~55_2℃)、清洁的环境,并且保持 良好的通风状态。 本系统软件属于我公司专有产品,未经同意,请勿复制,否则影响机 器稳定概不负责,并将通过有关法律渠道追究盗版责任。 功能特点(H.264压缩) 压缩方式:H.264/MPEG 4; 显示分辨率:1024_768、1280_1024、16:9宽屏、16:10宽屏; 预览分辨率 (可调) :704_576(PAL制),740_480(NTSC制); 352_288(PAL制),370_240(NTSC制); 录像分辨率(所见即所得):704_576(PAL制), 740_480(NTSC制); 352_288(PAL制),370_240(NTSC制); 单机容量支持12路D1、48路CIF; 支持单画面、4画面、9画面、16画面、20画面、25画面显示,可全屏显示,支持自动 翻页; 多画面实时显示/录像/回放功能,支持多协议云镜控制,支持多种报警盒实现联动报警; 手动录像、连续录像、定时录像、动态录像、事件录像、联动报警录像等多种录像方式; 可以设置每个通道的显示名称; NTSC/PAL两种视频显示制式可选, 25帧/秒实时预览、录像、回放; 视频图像属性调节功能,使图像更清晰。 视频录像图像质量有多种等级可调,以改变存储文件大小,方便不同场合应用。 视频移动报警录像功能,报警录像灵敏度、预录像时间、延迟录像时间可调,支持声音 报警输出。 智能检索,可按摄像镜头年/月/日/时间段或长时间连续检索回放,自动检索报警录像, 能区分录像事件。 具有局部放大功能,可逐帧回放,快速播放,慢速播放,常规播放。 回放时可进行图片抓拍功能,回放时文件备份功能、文件剪辑功能。 可进行远程监控,远程控制云镜、色彩、手动录像、布撤防、重启计算机等控制工作。 支持现今最大容量的硬盘,并支持安装多个大容量的硬盘。 硬盘管理可以通过对最大使用硬盘和硬盘最小预留空间的设置使硬盘能够得到充分合理 的使用。 自动创建日志文件(用户操作日志、系统日志、远程控制日志),便于查询操作记录。 系统可任意设置定时关机,定时重启功能,保证系统运行的高稳定性。 可设定开机自动运行监控软件,断电自动关闭程序,来电自动重启,自动恢复录像。 硬件、软件经过严格的拷机试验,稳定可靠。 系统硬件配置要求低,48路同时录像显示时,CPU的占用率低于75%。 系统能有效防止用户多次重复运行监控系统导致系统崩溃的情况。 目录 第一部分 软件安装与卸载..............................................................................................................6 1.1 系统要求 ..................................................................................................................................................6 1.1.1 硬件要求(推荐) ................................................................................

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值