// 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
查看更多评论