-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstabilizer.hpp
56 lines (44 loc) · 1.5 KB
/
stabilizer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <Eigen/Dense>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include "alignment.hpp"
#include "smoother.hpp"
struct VideoStabilizerParams {
VideoAlignerParams aligner;
// Lag: number of frames to delay before smoothing
int lag = 3;
int smoother_memory = 8;
double lambda = 10.0;
// Enable smoother: if false, just use the aligner
bool enable_smoother = true;
// Crop pixels: if > 0, crop the output image by this amount
int crop_pixels = 32;
// Displacement thresholds for decay and full reset
double min_disp = 32.0, max_disp = 96.0;
double min_decay = 0.95, max_decay = 0.5;
};
class VideoStabilizer {
public:
VideoStabilizer(const VideoStabilizerParams& params = VideoStabilizerParams());
/**
* Process one frame and return the stabilized frame if available;
* otherwise return an empty cv::Mat until enough frames have arrived.
*/
cv::Mat processFrame(const cv::Mat& inputFrame);
protected:
VideoStabilizerParams m_params;
VideoAligner aligner;
int m_frameIndex = 0;
int alignFailures = 0;
L1SmootherCenter m_l1Smoother;
// For each frame i, we store a measured transform from frame i-1 to i
// (i.e. T_i) once alignment is done.
std::deque<SimilarityTransform> m_measurementBuffer;
// We also keep around all input frames until it's time to pop them
std::deque<cv::Mat> m_frameBuffer;
SimilarityTransform m_accum;
};