OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
CVStabilization.h
Go to the documentation of this file.
1
10// Copyright (c) 2008-2019 OpenShot Studios, LLC
11//
12// SPDX-License-Identifier: LGPL-3.0-or-later
13
14#ifndef OPENSHOT_STABILIZATION_H
15#define OPENSHOT_STABILIZATION_H
16
17#define int64 opencv_broken_int
18#define uint64 opencv_broken_uint
19#include <opencv2/opencv.hpp>
20#include <opencv2/core.hpp>
21#undef uint64
22#undef int64
23
24#include <map>
25#include <string>
26#include <vector>
27
29
30#include "Clip.h"
31#include "Json.h"
32
33// Forward decl
34namespace pb_stabilize {
35 class Frame;
36}
37
38// Store the relative transformation parameters between consecutive frames
40{
42 TransformParam(double _dx, double _dy, double _da) {
43 dx = _dx;
44 dy = _dy;
45 da = _da;
46 }
47
48 double dx;
49 double dy;
50 double da; // angle
51};
52
53// Stores the global camera trajectory for one frame
55{
57 CamTrajectory(double _x, double _y, double _a) {
58 x = _x;
59 y = _y;
60 a = _a;
61 }
62
63 double x;
64 double y;
65 double a; // angle
66};
67
68
76
77 private:
78
79 int smoothingWindow; // In frames. The larger the more stable the video, but less reactive to sudden panning
80
81 size_t start;
82 size_t end;
83 double avr_dx, avr_dy, avr_da, max_dx, max_dy, max_da;
84
85 cv::Mat last_T;
86 cv::Mat prev_grey;
87 std::vector <TransformParam> prev_to_cur_transform; // Previous to current
88 std::string protobuf_data_path;
89
90 uint progress;
91 bool error = false;
92
94 ProcessingController *processingController;
95
97 bool TrackFrameFeatures(cv::Mat frame, size_t frameNum);
98
99 std::vector<CamTrajectory> ComputeFramesTrajectory();
100 std::map<size_t,CamTrajectory> SmoothTrajectory(std::vector <CamTrajectory> &trajectory);
101
103 std::map<size_t,TransformParam> GenNewCamPosition(std::map <size_t,CamTrajectory> &smoothed_trajectory);
104
105 public:
106
107 std::map <size_t,CamTrajectory> trajectoryData; // Save camera trajectory data
108 std::map <size_t,TransformParam> transformationData; // Save transormation data
109
111 CVStabilization(std::string processInfoJson, ProcessingController &processingController);
112
114 void stabilizeClip(openshot::Clip& video, size_t _start=0, size_t _end=0, bool process_interval=false);
115
118 bool SaveStabilizedData();
120 void AddFrameDataToProto(pb_stabilize::Frame* pbFrameData, CamTrajectory& trajData, TransformParam& transData, size_t frame_number);
121
122 // Return requested struct info for a given frame
125
126 // Get and Set JSON methods
127 void SetJson(const std::string value);
128 void SetJsonValue(const Json::Value root);
129
130 // Load protobuf data file (ONLY FOR MAKE TEST)
131 bool _LoadStabilizedData();
132};
133
134#endif
Header file for Clip class.
Header file for JSON class.
This is a message class for thread safe comunication between ClipProcessingJobs and OpenCV classes.
This class stabilizes a video frame using optical flow.
TransformParam GetTransformParamData(size_t frameId)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void AddFrameDataToProto(pb_stabilize::Frame *pbFrameData, CamTrajectory &trajData, TransformParam &transData, size_t frame_number)
Add frame stabilization data into protobuf message.
std::map< size_t, TransformParam > transformationData
void stabilizeClip(openshot::Clip &video, size_t _start=0, size_t _end=0, bool process_interval=false)
Process clip and store necessary stabilization data.
std::map< size_t, CamTrajectory > trajectoryData
CamTrajectory GetCamTrajectoryTrackedData(size_t frameId)
void SetJson(const std::string value)
Load JSON string into this object.
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
CamTrajectory(double _x, double _y, double _a)
TransformParam(double _dx, double _dy, double _da)