| 
    OpenShot Library | libopenshot
    0.4.0
    
   | 
 
 
 
 
Go to the documentation of this file.
   20 #include "stabilizedata.pb.h" 
   22 #include <google/protobuf/util/time_util.h> 
   26 using google::protobuf::util::TimeUtil;
 
   29 Stabilizer::Stabilizer(std::string clipStabilizedDataPath):protobuf_data_path(clipStabilizedDataPath)
 
   32     init_effect_details();
 
   41     init_effect_details();
 
   45 void Stabilizer::init_effect_details()
 
   54     info.
description = 
"Stabilize video clip to remove undesired shaking and jitter.";
 
   57     protobuf_data_path = 
"";
 
   67     cv::Mat frame_image = frame->GetImageCV();
 
   70     if(!frame_image.empty()){
 
   75             float zoom_value = zoom.
GetValue(frame_number);
 
   78             cv::Mat T(2,3,CV_64F);
 
   90             cv::Mat frame_stabilized;
 
   91             cv::warpAffine(frame_image, frame_stabilized, T, frame_image.size());
 
   94             cv::Mat T_scale = cv::getRotationMatrix2D(cv::Point2f(frame_stabilized.cols/2, frame_stabilized.rows/2), 0, zoom_value);
 
   95             cv::warpAffine(frame_stabilized, frame_stabilized, T_scale, frame_stabilized.size());
 
   96             frame_image = frame_stabilized;
 
  101     frame->SetImageCV(frame_image);
 
  109     pb_stabilize::Stabilization stabilizationMessage;
 
  112     std::fstream input(inputFilePath, ios::in | ios::binary);
 
  113     if (!stabilizationMessage.ParseFromIstream(&input)) {
 
  114         std::cerr << 
"Failed to parse protobuf message." << std::endl;
 
  123     for (
size_t i = 0; i < stabilizationMessage.frame_size(); i++) {
 
  126         const pb_stabilize::Frame& pbFrameData = stabilizationMessage.frame(i);
 
  129         size_t id = pbFrameData.id();
 
  132         float x = pbFrameData.x();
 
  133         float y = pbFrameData.y();
 
  134         float a = pbFrameData.a();
 
  140         float dx = pbFrameData.dx();
 
  141         float dy = pbFrameData.dy();
 
  142         float da = pbFrameData.da();
 
  149     google::protobuf::ShutdownProtobufLibrary();
 
  169     root[
"protobuf_data_path"] = protobuf_data_path;
 
  186     catch (
const std::exception& e)
 
  189         throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
 
  200     if (!root[
"protobuf_data_path"].isNull()){
 
  201         protobuf_data_path = (root[
"protobuf_data_path"].asString());
 
  204             std::cout<<
"Invalid protobuf data path";
 
  205             protobuf_data_path = 
"";
 
  208     if(!root[
"zoom"].isNull())
 
  218     root[
"zoom"] = 
add_property_json(
"Zoom", zoom.
GetValue(requested_frame), 
"float", 
"", &zoom, 0.0, 2.0, 
false, requested_frame);
 
  221     return root.toStyledString();
 
  
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
 
const Json::Value stringToJson(const std::string value)
 
EffectInfoStruct info
Information about the current effect.
 
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
 
std::string Json() const override
Generate JSON string of this object.
 
This namespace is the default namespace for all code in the openshot library.
 
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
 
std::map< size_t, EffectCamTrajectory > trajectoryData
 
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
 
Header file for Stabilizer effect class.
 
std::string PropertiesJSON(int64_t requested_frame) const override
 
bool LoadStabilizedData(std::string inputFilePath)
Load protobuf data file.
 
Json::Value JsonValue() const
Generate Json::Value for this object.
 
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
 
std::map< size_t, EffectTransformParam > transformationData
 
Exception for invalid JSON.
 
bool has_audio
Determines if this effect manipulates the audio of a frame.
 
Json::Value JsonValue() const override
Generate Json::Value for this object.
 
void SetJson(const std::string value) override
Load JSON string into this object.
 
std::string id
ID Property for all derived Clip and Effect classes.
 
std::string class_name
The class name of the effect.
 
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number) override
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
 
std::string description
The description of this effect and what it does.
 
bool has_video
Determines if this effect manipulates the image of a frame.
 
std::string name
The name of the effect.
 
Header file for all Exception classes.
 
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
 
double GetValue(int64_t index) const
Get the value at a specific index.