opecv3.0 视频稳像
来源:互联网 发布:mac 开机慢 编辑:程序博客网 时间:2024/04/30 02:31
#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 stabilizerStabilizerBase *stabilizer = 0;// first, prepare the one or two pass stabilizerbool isTwoPass = 1;int radius_pass = 15;if (isTwoPass){// with a two pass stabilizerbool est_trim = true;TwoPassStabilizer *twoPassStabilizer = new TwoPassStabilizer();twoPassStabilizer->setEstimateTrimRatio(est_trim);twoPassStabilizer->setMotionStabilizer(makePtr<GaussianMotionFilter>(radius_pass));stabilizer = twoPassStabilizer;}else{// with an one pass stabilizerOnePassStabilizer *onePassStabilizer = new OnePassStabilizer();onePassStabilizer->setMotionFilter(makePtr<GaussianMotionFilter>(radius_pass));stabilizer = onePassStabilizer;}// second, set up the parametersint 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 framesstabFrames.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://web.cecs.pdx.edu/~fliu/project/subspace_stabilization/
参考:http://blog.csdn.net/gone_huilin/article/details/53224104
阅读全文
0 0
- opecv3.0 视频稳像
- 视频稳像
- 视频稳像笔记
- opencv3 视频稳像
- 视频稳像(科普)
- 视频稳像 video stabilization
- 视频稳像(Video Stabilization)
- 子空间视频稳像原文理解
- 无人机视频的电子稳像
- 实时视频抠像
- 视频实时抠像
- 视频抠像算法
- QT+opecv3.2图像显示
- VS2008+OPECV3.0.0+DirectShow 配置方法
- OpenCV3.0.0下的视频稳像代码,效果不错哦!
- 视频抠像软件Imagineer Systems Mokey
- 蓝背抠像 绿背抠像 算法,实时视频抠像算法 视频直播抠像
- ubuntu16.04 Qt5.8 如何使用opecv3.2
- android PopupWindow的使用和分析
- unix网络编程 学习笔记(精华)
- RecyclerView Adapter Helper
- html5canvas:教你实现知乎登录动态粒子背景
- linux服务器网络配置_自动获取ip_手动设置静态ip
- opecv3.0 视频稳像
- TI培训资料
- 【腾讯TMQ】【测试左移专栏】用Powermock和Mockito来做安卓单元测试
- MyEclipse创建javaweb项目
- Python学习手册(第五部分)
- MFC CTIME 对象之间时间差 CTimeSpan
- Java高级-线程同步lock与unlock使用
- mybatis sum函数返回为null的解决方式,格式化小数千分位的问题
- 关于scanf函数输入及小题目回顾