// videostabDemo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//#include <iostream>#include <opencv2/opencv.hpp>
#include <opencv2/videostab.hpp>
#include <string>
#include <iostream>#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<IFrameSource> 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 << stabFrame;}imshow("stabFrame", stabFrame);// esc键退出char key = static_cast<char>(waitKey(100));if (key == 27){cout << endl;break;}}writer.release();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();}
}//对于实时视频流,使用缓存50帧来处理
int main(int argc, char* argv[])
{Ptr<IFrameSource> stabFrames;// 输入输出视频准备cacStabVideo(stabFrames, inputPath);stabFrames.release();getchar();return 0;
}

opencv4.2.0 视频去抖动算法代码相关推荐

  1. 暗通道去雾算法代码实现(1) python

    文章目录 前言 一.腐蚀膨胀操作 二.何凯明去雾论文思想的简单描述 1.关于暗通道先验 2.暗通道先验的理论依据: 3.有雾图像的形成模型 4.传输率t的估计 5.大气光的估计 6.使用导向滤波对传输 ...

  2. 基于python实现opencv视频去抖动

  3. 图像和视频的快速去雾算法研究

    王昕, 孙莹莹, 李影昉. 图像和视频的快速去雾算法研究[J]. 影像科学与光化学, 2016, 34(1): 82-87.   WANG Xin, SUN Yingying, LI Yingfang ...

  4. 综述:视频和图像去雾算法以及相关的图像恢复和增强研究

    综述:视频和图像去雾算法以及相关的图像恢复和增强研究 翻译自IEEE的一篇文章<Review of Video and Image Defogging Algorithms and Relate ...

  5. matlab去雾处理是视频,一种快速视频去雾方法与流程

    本发明涉及视频处理技术领域,尤其是一种快速视频去雾方法. 背景技术: 雾霾条件下拍摄的视频,受到大气环境的影响,会产生退化和失真,这些视频无法反应真实场景的信息.视频去雾是通过一定技术处理,去除雾霾的 ...

  6. OpenCV4中有哪些视频背景/前景分割(背景建模/前景提取)算法的类,它们各自的算法原理、特点是什么,并附示例代码

    关于OpenCV4中有哪些视频背景/前景分割(背景建模/前景提取)算法的类,汇总如下: 上面的汇总不仅显示了OpenCV4中有哪些视频背景/前景分割(背景建模/前景提取)算法的类,还显示了它们的继承. ...

  7. Python 还能实现图片去雾?FFA 去雾算法、暗通道去雾算法用起来!(附代码)...

    授权自AI科技大本营(ID:rgznai100) 本文约3600字,建议阅读7分钟. 本文为你介绍FFA去雾算法和暗通道去雾算法搭建. 在过去的几十年中,单图像去雾作为基本的低级视觉任务已引起了计算机 ...

  8. Python 还能实现图片去雾?FFA 去雾算法、暗通道去雾算法用起来! | 附代码

    在过去的几十年中,单图像去雾作为基本的低级视觉任务已引起了计算机视觉社区和人工智能公司的越来越多的关注.其中最为典型的便是北大&北航提出FFA-Net去雾新网络和何凯明博士提出的暗通道去雾算法 ...

  9. 股票量化分析工具V2.0版-视频更新完毕!代码已上传!

    视频课程<理性投资!2天入门量化思维炒股!定制自己的股票分析工具>Day1录播内容已全部上线. 已经购买的读者们速去学习!!! ----点击[阅读原文]跳转 升级的V2.0回测工具的代码已 ...

最新文章

  1. 安装版 修改mysql最大连接数_修改MySQL最大连接数
  2. 网站建设中的五大常见问题
  3. Golang结构体struct的使用(结构体嵌套, 匿名结构体等)
  4. 全面解析java注解
  5. oracle getsqltxt函数,Oracle 性能优化的基本方法概述(2)
  6. Java多线程编程中Future模式的详解
  7. js如何提高for循环的效率_如何提高rv减速机的散热效率
  8. 3D应用开发中的欧拉角和旋转矩阵
  9. 计算机硬件测试流程,驱动精灵如何检测电脑硬件 检测硬件看完你就懂了
  10. 数据分析——常见数据指标汇总
  11. DM DBLINK使用笔记
  12. modeler 连接oracle,用 IBM SPSS Modeler 整合不同数据库之间的数据
  13. BUUCTF [WUSTCTF2020]alison_likes_jojo
  14. Nginx 基本理论和安装
  15. configure命令的使用
  16. MBA-day22 直言命题的矛盾命题
  17. 湖南省永州市谷歌高清卫星地图下载
  18. 图像矫正:桶形畸变矫正的原理及python简易实现与加速
  19. oracle sql 历史 监控,ORACLE 管理,SQL 篇--监控
  20. opc-ua协议机器数据采集-python

热门文章

  1. java 反转 控制 注入_控制反转和依赖注入
  2. hibernate mysql 模糊查询_服务器-hibernate操作mysql,模糊查询时中文查不到,数字和英文可以查到...
  3. vsc系统是什么意思_电脑蓝屏是什么意思?蓝屏就一定要重装系统吗?你可不要弄错了...
  4. 百度搜索结果 转换_如何让图片出现在百度搜索结果里出现?
  5. java string 返回匹配正则的字符串的起始位置_Python小课堂正则表达式
  6. Python_基础_1
  7. 第九天2017/04/18(1、友元函数、运算符重载)
  8. 【自动驾驶】10.百度Apollo平台 事件通信机制
  9. Spring系列之beanFactory与ApplicationContext
  10. tomcat文件目录结构及功能介绍