当前位置: 首页 > 编程日记 > 正文

opencv3 视频稳像

OpneCV3.x中提供了专门应用于视频稳像技术的模块,该模块包含一系列用于全局运动图像估计的函数和类。结构体videostab::RansacParams实现了RANSAC算法,这个算法用来实现连续帧间的运动估计。videostab::MotionEstimatorBase是基类中所有全局运动估计方法,videostab::MotionEstimatorRansacL2描述了一个健壮的RANSAC-based全局二维估计方法的最小化L2误差。
#include <opencv2/opencv.hpp>
#include <opencv2/videostab.hpp>
#include <string>
#include <iostream>using namespace std;
using namespace cv;
using namespace cv::videostab;string inputPath = "inputVideo.avi";
string outputPath = "outputVideo.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(100));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(int argc, char* argv[])
{Ptr<IFrameSource> stabFrames;// 输入输出视频准备cacStabVideo(stabFrames, inputPath);stabFrames.release();return 0;
}

相关文章:

perf+火焰图 = 性能分析利器

perf 1. perf安装 sudo apt install linux-tools-common检查是否安装好 perf如果出现 You may need to install the following packages for this specific kernel:推荐安装可以按照提示将推荐安装包全部安装好 sudo apt-get install linux-tools-对应版本-generic linux-c…

3- MySQL数据类型

MySQL表字段类型 MySQL数据表的表示一个二维表&#xff0c;由一个或多个数据列构成。 每个数据列都有它的特定类型&#xff0c;该类型决定了MySQL如何看待该列数据&#xff0c;并且约束列存放相应类型的数据。 MySQL中的列表有三种&#xff1a;数值类&#xff0c;字符串类和日期…

AddressSanitizer+cmake

1. AddressSanitizercmake(Linux) 编译指令&#xff1a; CXXFLAGS通常需要加上 -fsanitizeaddress -fno-omit-frame-pointer #打印函数调用路径 -fsanitize-recoveraddress #AddressSanitizer遇到错误时能够继续-fsanitizeaddress-fno-omit-frame-pointer-fsanitize-rec…

vibe前景提取改进算法

// improveVibeAlgorithm.h #ifndef IMPROVED_VIBE_ALGORITHM_H #define IMPROVED_VIBE_ALGORITHM_H#include <opencv2/opencv.hpp> using namespace std;#define WINSIZE 5 // Vibe改进算法, Barnich, Olivier & Droogenbroeck, Marc. (2009). // ViBE: A powerfu…

npm-debug.log文件出现原因

项目主目录下总是会出现这个文件&#xff0c;而且不止一个&#xff0c;原因是npm i 的时候&#xff0c;如果报错&#xff0c;就会增加一个此文件来显示报错信息&#xff0c;npm install的时候则不会出现。转载于:https://www.cnblogs.com/liuna/p/6558006.html

AutoFac Ioc依赖注入容器

本文原著&#xff1a;牛毅 原文路径 http://niuyi.github.io/blog/2012/04/06/autofac-by-unit-test/ 理解IOC容器请看下图&#xff1a; 没有使用IOC容器的情况下: 使用IOC容器的情况下&#xff1a; 去掉IOC容器的情况后&#xff1a; IOC容器又像一个插座&#xff0c;将电输送…

Linux安装App记录

Ubuntu18.04安装微信

windows socket编程入门示例3

// Lock.h #ifndef _Lock_H #define _Lock_H #include <windows.h>class CriticalSection { private:CRITICAL_SECTION g_cs; //临界区 public:CriticalSection();~CriticalSection();void Lock();void UnLock(); }; #endif// Lock.cpp #include "Lock.h"…

游戏开发:js实现简单的板球游戏

js实现简单的板球游戏大家好&#xff0c;本次我们来使用js来实现一个简单的板球游戏。截图如下&#xff1a;首先&#xff0c;设计页面代码&#xff0c;页面代码很简单&#xff0c;因为整个几乎是使用js编写的&#xff0c;页面几乎没有代码&#xff0c;如下&#xff1a;<!DOC…

SLAM精度测评——EVO进阶

1. 基本概念 1.1 Umeyama算法 ATE&#xff1a; evo_ape tum state_groundtruth_estimate0/data.tum orb2/CameraTrajectory.txt -r trans_part -va --plot --plot_mode xy --save_results /home/sun/evo/v1_01_easy/orb2/ate.zip RPE&#xff1a; evo_rpe tum state_groun…

python读取图片并且显示

使用python-opencv读取图片&#xff0c;利用opencv或matplotlib显示图片。 # -*- coding: utf-8 -*-import numpy as np from matplotlib import pyplot as plt #import urllib import cv2def load_image1(file):# Load an color image in grayscaleimg cv2.imread(file,0)cv…

shiro认证

shiro权限认证&#xff1a; 具体的认证流程是这样的&#xff1a; 一般流程&#xff1a; 通过.ini的文件来初始化工厂&#xff0c;.ini的文件的好处是可以创建多个组&#xff0c;而.properties的文件只能创建一组。 系统默认有shiro.ini的文件&#xff0c;但是一般我们是自定义数…

小猿圈Linux基础面试题,看看你能答对几道?

最近身边的很多朋友都在学习linux&#xff0c;从最开始的安装软件都需要百度一天的他们&#xff0c;现在已经成长为了&#xff0c;不需要百度就可以把自己弄懵圈的了&#xff0c;接下来的几天小猿圈linux老师会为大家准备一些实用的linux技巧分析给大家&#xff0c;希望对你有所…

ORB-SLAM2 论文翻译

https://ug98gs7tbw.feishu.cn/docs/doccnKKOWAjkKv7AzAiEvbnM3Tf

mxnet教程1

import mxnet as mx #%matplotlib inline import os import subprocess import numpy as np import matplotlib.pyplot as plt import tarfileimport warnings warnings.filterwarnings("ignore", categoryDeprecationWarning)# 从内存中读取数据 def test1():data …

番外:Spring MVC环境搭建和Mybatis配置避坑篇

2019独角兽企业重金招聘Python工程师标准>>> web.xml引入对spring mvc的支持&#xff1b; spring-mvc配置spring-mvc&#xff1b; spring-mybatis配置mybatis支持&#xff0c;并指名mapper文件的位置&#xff1b; mybaits-config配置mybatis&#xff1b; jdbc.prope…

50个云终端只需一台服务器是怎么一回事

看到这个标题也许有人会说50个云终端只需要一台服务器这应该是不可能的吧&#xff0c;即使是真的那这个服务器的配置和价格应该也要非常高的吧。但是如果有人和你说50个云终端只需要一台中等配置和价格的服务器就可以的呢。而且这50个用户桌面都可以正常的使用不会出现卡顿等现…

SLAM学习,小白入门到殿堂级大牛资料整理

总结一下我接触过的SLAM算法吧,主要集中在visual slam: 特征法: ORB SLAM https://github.com/raulmur/ORB_SLAM2优势: 在静态环境下定位准确,稳定, 单目和双目版本都可以达到实时(高于10frames/s)。代码可读性强,易扩展, 网上也有实现和imu融合的版本。 劣势:建的地图…

python解析json

“data.json”文件内容如下&#xff1a; {"id":"1220562","alt":"http:\/\/book.douban.com\/book\/1220562","rating":{"max":10, "average":"7.0", "numRaters":282, "min…

8.改进应用程序

2019独角兽企业重金招聘Python工程师标准>>> ##8.1数字格式设置&#xff08;storyboard&#xff09; ##8.1.2可选类型拆封 import Cocoa extension Double{var dollars : String{let formatter : NumberFormatter NumberFormatter()//NSNumberFormatter弃用var re…

小猿圈Linux学习-Linux种搜索的命令

做Linux工程师的每天都不能少的工作就是搜索文件&#xff0c;这是他们的日常活动&#xff0c;很繁琐很枯燥&#xff0c;所以我们就需要知道一些搜索的命令&#xff0c;这些命令更高效更快捷&#xff0c;今天小猿圈就给大家分享4个可以搜索的Linux命令。。 方法 1&#xff1a;使…

SURF与SIFT比较分析

opencv3.2 SURF实现特征点匹配 opencv3.2中SurfFeatureDetector、SurfDescriptorExtractor、BruteForceMatcher这三个的使用方法已经和原先2.4版本前不一样了。 使用方法示例如下&#xff1a; Ptr<SURF> detector SURF::create(minHessian);detector->detect(img_1…

python文件和目录

# -*- coding: utf-8 -*-import osdef printFile(rootDir):allFiles os.listdir(rootDir) #列出文件夹下所有文件和目录for i in range(0, len(allFiles)):# print(rootDir allFiles[i])path os.path.join(rootDir, allFiles[i])if not os.path.isfile(path):print(path, &q…

你不怕他离职吗?

图片来自“wikiart” 这是我同事在晚上11点多跟我聊微信时问起的一个问题&#xff0c;我觉得这个问题还是挺有代表性的&#xff0c;所以我还是决定就这个问题展开聊聊我对这句话的看法。 我同事之所以这么说&#xff0c;是因为他的组员&#xff0c;也就是问题中的那个他&#x…

tensorflow 1

import tensorflow as tf import numpy as np import matplotlib.pylab as pltdef tfDemo1():#create datax_data np.random.rand(100).astype(np.float32)y_data x_data * 0.1 0.3#create tensorflow structureWeightstf.Variable(tf.random_uniform([1],-1.0,1.0)) #一维&…

SLAM资源整理

资源整理 浙大3D Group VINS orbslam2 orbslam2 video study https://www.bilibili.com/video/BV1bK4y197kB/?spm_id_fromautoNext orbslam2 csdn https://blog.csdn.net/ncepu_chen/category_9874746.html https://www.zhihu.com/column/c_1114864226103037952 https:…

Golang微服务开发实践

github: github.com/yun-mu/Micr… 微服务概念学习&#xff1a;可参考 Nginx 的微服务文章 微服务最佳实践&#xff1a;可参考 微服务最佳实践 demo 简介 服务&#xff1a; consignment-service&#xff08;货运服务&#xff09;user-service&#xff08;用户服务&#xff09;l…

Linux ssh/scp/docker学习

文章目录Linux ssh/scp/docker使用学习1. ssh 登录2. scp传输文件3. docker4. git checkout 替换指定分支的单个文件Linux ssh/scp/docker使用学习 1. ssh 登录 sudo ssh fireflyip (登录账号密码) scp -r company/data_depthfill/ firefly192.168.105.6:/tmp/ ​​​​ 2…

tensorflow mnist 1

import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import keras.backend.tensorflow_backend as KTFdef add_layer(inputs,in_size,out_size,activation_functionNone):#Weights是一个矩阵&#xff0c;[行&#xff0c;列]为[in_size,out_s…

framework7使用笔记

2019独角兽企业重金招聘Python工程师标准>>> myApp.addView(.view-main, {}); 以上这句代码一定要添加 &#xff0c;否则链接的页面不能正常加载 --------------------------------------------- 如果初始化时定义了preprocess&#xff0c;则页面上链接的自动加载将…