Loading...
Searching...
No Matches
CVStabilization.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_STABILIZATION_H
#define OPENSHOT_STABILIZATION_H
#define int64 opencv_broken_int
#define uint64 opencv_broken_uint
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#undef uint64
#undef int64
#include <map>
#include <string>
#include <vector>
#include "ProcessingController.h"
#include "Clip.h"
#include "Json.h"
// Forward decl
namespace pb_stabilize {
class Frame;
}
// Store the relative transformation parameters between consecutive frames
struct TransformParam
{
TransformParam() {}
TransformParam(double _dx, double _dy, double _da) {
dx = _dx;
dy = _dy;
da = _da;
}
double dx;
double dy;
double da; // angle
};
// Stores the global camera trajectory for one frame
struct CamTrajectory
{
CamTrajectory() {}
CamTrajectory(double _x, double _y, double _a) {
x = _x;
y = _y;
a = _a;
}
double x;
double y;
double a; // angle
};
class CVStabilization {
private:
int smoothingWindow; // In frames. The larger the more stable the video, but less reactive to sudden panning
size_t start;
size_t end;
double avr_dx, avr_dy, avr_da, max_dx, max_dy, max_da;
cv::Mat last_T;
cv::Mat prev_grey;
std::vector <TransformParam> prev_to_cur_transform; // Previous to current
std::string protobuf_data_path;
uint progress;
bool error = false;
ProcessingController *processingController;
bool TrackFrameFeatures(cv::Mat frame, size_t frameNum);
std::vector<CamTrajectory> ComputeFramesTrajectory();
std::map<size_t,CamTrajectory> SmoothTrajectory(std::vector <CamTrajectory> &trajectory);
std::map<size_t,TransformParam> GenNewCamPosition(std::map <size_t,CamTrajectory> &smoothed_trajectory);
public:
std::map <size_t,CamTrajectory> trajectoryData; // Save camera trajectory data
std::map <size_t,TransformParam> transformationData; // Save transormation data
CVStabilization(std::string processInfoJson, ProcessingController &processingController);
void stabilizeClip(openshot::Clip& video, size_t _start=0, size_t _end=0, bool process_interval=false);
bool SaveStabilizedData();
void AddFrameDataToProto(pb_stabilize::Frame* pbFrameData, CamTrajectory& trajData, TransformParam& transData, size_t frame_number);
// Return requested struct info for a given frame
TransformParam GetTransformParamData(size_t frameId);
CamTrajectory GetCamTrajectoryTrackedData(size_t frameId);
// Get and Set JSON methods
void SetJson(const std::string value);
void SetJsonValue(const Json::Value root);
// Load protobuf data file (ONLY FOR MAKE TEST)
bool _LoadStabilizedData();
};
#endif
Clip.h
Header file for Clip class.
Json.h
Header file for JSON class.
ProcessingController.h
This is a message class for thread safe comunication between ClipProcessingJobs and OpenCV classes.
CVStabilization::GetTransformParamData
TransformParam GetTransformParamData(size_t frameId)
Definition CVStabilization.cpp:314
CVStabilization::_LoadStabilizedData
bool _LoadStabilizedData()
Definition CVStabilization.cpp:374
CVStabilization::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition CVStabilization.cpp:356
CVStabilization::CVStabilization
CVStabilization(std::string processInfoJson, ProcessingController &processingController)
Set default smoothing window value to compute stabilization.
Definition CVStabilization.cpp:29
CVStabilization::AddFrameDataToProto
void AddFrameDataToProto(pb_stabilize::Frame *pbFrameData, CamTrajectory &trajData, TransformParam &transData, size_t frame_number)
Add frame stabilization data into protobuf message.
Definition CVStabilization.cpp:298
CVStabilization::transformationData
std::map< size_t, TransformParam > transformationData
Definition CVStabilization.h:108
CVStabilization::stabilizeClip
void stabilizeClip(openshot::Clip &video, size_t _start=0, size_t _end=0, bool process_interval=false)
Process clip and store necessary stabilization data.
Definition CVStabilization.cpp:37
CVStabilization::trajectoryData
std::map< size_t, CamTrajectory > trajectoryData
Definition CVStabilization.h:107
CVStabilization::GetCamTrajectoryTrackedData
CamTrajectory GetCamTrajectoryTrackedData(size_t frameId)
Definition CVStabilization.cpp:326
CVStabilization::SaveStabilizedData
bool SaveStabilizedData()
Definition CVStabilization.cpp:268
CVStabilization::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition CVStabilization.cpp:339
ProcessingController
Definition ProcessingController.h:20
openshot::Clip
This class represents a clip (used to arrange readers on the timeline).
Definition Clip.h:89
pb_stabilize
Definition CVStabilization.h:34
CamTrajectory
Definition CVStabilization.h:55
CamTrajectory::x
double x
Definition CVStabilization.h:63
CamTrajectory::CamTrajectory
CamTrajectory(double _x, double _y, double _a)
Definition CVStabilization.h:57
CamTrajectory::y
double y
Definition CVStabilization.h:64
CamTrajectory::CamTrajectory
CamTrajectory()
Definition CVStabilization.h:56
CamTrajectory::a
double a
Definition CVStabilization.h:65
TransformParam
Definition CVStabilization.h:40
TransformParam::TransformParam
TransformParam()
Definition CVStabilization.h:41
TransformParam::dx
double dx
Definition CVStabilization.h:48
TransformParam::dy
double dy
Definition CVStabilization.h:49
TransformParam::TransformParam
TransformParam(double _dx, double _dy, double _da)
Definition CVStabilization.h:42
TransformParam::da
double da
Definition CVStabilization.h:50