您当前的位置: 首页 >  opencv

phymat.nico

暂无认证

  • 3浏览

    0关注

    1967博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

opencv4.2.0 视频去抖动算法代码

phymat.nico 发布时间:2020-04-22 22:29:32 ,浏览量:3

// videostabDemo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//


#include 

#include 
#include 
#include 
#include 

#pragma comment(lib, "opencv_core420.lib")
#pragma comment(lib, "opencv_videoio420.lib")
#pragma comment(lib, "opencv_highgui420.lib")
#pragma comment(lib, "opencv_features2d420.lib")
#pragma comment(lib, "opencv_videostab420.lib")

using namespace std;
using namespace cv;
using namespace cv::videostab;

string inputPath = "video_seq_2.avi";
string outputPath = "outputstab001.avi";//001 must

// 视频稳定输出
void videoOutput(Ptr stabFrames, string outputPath)
{
	VideoWriter writer;
	cv::Mat stabFrame;
	int nframes = 0;
	// 设置输出帧率
	double outputFps = 10;
	// 遍历搜索视频帧
	while (!(stabFrame = stabFrames->nextFrame()).empty())
	{
		nframes++;
		// 输出视频稳定帧
		if (!outputPath.empty())
		{
			if (!writer.isOpened())
				writer.open(outputPath, VideoWriter::fourcc('M', 'J', 'P', 'G'), outputFps, stabFrame.size());

			writer 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(stabilizer));
		// 4-videoOutput the stabilized frames. The results are showed and saved.
		videoOutput(stabFrames, outputPath);
	}

	catch (const exception &e)
	{
		cout             
关注
打赏
1659628745
查看更多评论
0.0671s