Skip to content

Commit e69f7b8

Browse files
committed
Added zoom to Stabilizer Effect
1 parent 6d6c156 commit e69f7b8

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

include/effects/Stabilizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ namespace openshot
9090
/// Init effect settings
9191
void init_effect_details();
9292
std::string protobuf_data_path;
93+
Keyframe zoom;
9394

9495
public:
9596
std::string teste;

src/CVStabilization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void CVStabilization::stabilizeClip(openshot::Clip& video, size_t _start, size_t
5151
}
5252

5353
// Extract and track opticalflow features for each frame
54-
for (frame_number = start; frame_number < end; frame_number++)
54+
for (frame_number = start; frame_number <= end; frame_number++)
5555
{
5656
// Stop the feature tracker process
5757
if(processingController->ShouldStop()){
@@ -67,7 +67,7 @@ void CVStabilization::stabilizeClip(openshot::Clip& video, size_t _start, size_t
6767
TrackFrameFeatures(cvimage, frame_number);
6868

6969
// Update progress
70-
processingController->SetProgress(uint(100*frame_number/end));
70+
processingController->SetProgress(uint(100*(frame_number-start)/(end-start)));
7171
}
7272

7373
// Calculate trajectory data

src/CVTracker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo
7777
}
7878

7979
// Loop through video
80-
for (frame = start; frame < end; frame++)
80+
for (frame = start; frame <= end; frame++)
8181
{
8282

8383
// Stop the feature tracker process
@@ -110,7 +110,7 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo
110110

111111
}
112112
// Update progress
113-
processingController->SetProgress(uint(100*frame_number/end));
113+
processingController->SetProgress(uint(100*(frame_number-start)/(end-start)));
114114
}
115115
}
116116

src/effects/Stabilizer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void Stabilizer::init_effect_details()
6363
info.has_audio = false;
6464
info.has_video = true;
6565
protobuf_data_path = "";
66-
66+
zoom = 1.0;
6767
}
6868

6969
// This method is required for all derived classes of EffectBase, and returns a
@@ -79,6 +79,8 @@ std::shared_ptr<Frame> Stabilizer::GetFrame(std::shared_ptr<Frame> frame, int64_
7979

8080
// Check if track data exists for the requested frame
8181
if(transformationData.find(frame_number) != transformationData.end()){
82+
83+
float zoom_value = zoom.GetValue(frame_number);
8284

8385
// Create empty rotation matrix
8486
cv::Mat T(2,3,CV_64F);
@@ -97,7 +99,7 @@ std::shared_ptr<Frame> Stabilizer::GetFrame(std::shared_ptr<Frame> frame, int64_
9799
cv::warpAffine(frame_image, frame_stabilized, T, frame_image.size());
98100

99101
// Scale up the image to remove black borders
100-
cv::Mat T_scale = cv::getRotationMatrix2D(cv::Point2f(frame_stabilized.cols/2, frame_stabilized.rows/2), 0, 1.04);
102+
cv::Mat T_scale = cv::getRotationMatrix2D(cv::Point2f(frame_stabilized.cols/2, frame_stabilized.rows/2), 0, zoom_value);
101103
cv::warpAffine(frame_stabilized, frame_stabilized, T_scale, frame_stabilized.size());
102104
frame_image = frame_stabilized;
103105
}
@@ -178,6 +180,7 @@ Json::Value Stabilizer::JsonValue() const {
178180
Json::Value root = EffectBase::JsonValue(); // get parent properties
179181
root["type"] = info.class_name;
180182
root["protobuf_data_path"] = protobuf_data_path;
183+
root["zoom"] = zoom.JsonValue();
181184

182185
// return JsonValue
183186
return root;
@@ -215,6 +218,8 @@ void Stabilizer::SetJsonValue(const Json::Value root) {
215218
protobuf_data_path = "";
216219
}
217220
}
221+
if(!root["zoom"].isNull())
222+
zoom.SetJsonValue(root["zoom"]);
218223
}
219224

220225
// Get all properties for a specific frame
@@ -229,6 +234,8 @@ std::string Stabilizer::PropertiesJSON(int64_t requested_frame) const {
229234
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
230235
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
231236

237+
root["zoom"] = add_property_json("Zoom", zoom.GetValue(requested_frame), "float", "", &zoom, 0.0, 2.0, false, requested_frame);
238+
232239
// Return formatted string
233240
return root.toStyledString();
234241
}

src/examples/Example_opencv.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ void displayClip(openshot::Clip &r9){
7171
cv::destroyAllWindows();
7272
}
7373

74+
75+
/*
76+
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
77+
78+
The following methods are just for getting JSON info to the pre-processing effects
79+
80+
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
81+
*/
82+
83+
7484
// Return JSON string for the tracker effect
7585
string trackerJson(cv::Rect2d r, bool onlyProtoPath){
7686
// Set the tracker
@@ -108,6 +118,16 @@ string stabilizerJson(bool onlyProtoPath){
108118
return "{" + protobuf_data_path + ", " + smoothing_window.str() + "}";
109119
}
110120

121+
string objectDetectionJson(bool onlyProtoPath){
122+
123+
// Construct all the composition of the JSON string
124+
string protobuf_data_path = "\"protobuf_data_path\": \"example_object_detection.data\"";
125+
126+
// Return only the the protobuf path in JSON format
127+
if(onlyProtoPath)
128+
return "{" + protobuf_data_path + "}";
129+
}
130+
111131
int main(int argc, char* argv[]) {
112132

113133
// Set pre-processing effects

tests/CVStabilizer_Tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ SUITE(CVStabilizer_Tests)
5555
c1.Open();
5656

5757
// Create stabilizer
58-
CVStabilization stabilizer("{\"protobuf_data_path\": \"stabilizer.data\"}", processingController);
58+
CVStabilization stabilizer("{\"protobuf_data_path\": \"stabilizer.data\", \"smoothing_window\": 30}", processingController);
5959

60-
// Stabilize clip for frames 0-20
61-
stabilizer.stabilizeClip(c1, 0, 20+1, true);
60+
// Stabilize clip for frames 0-21
61+
stabilizer.stabilizeClip(c1, 0, 21, true);
6262

6363
// Get stabilized data
6464
TransformParam tp = stabilizer.GetTransformParamData(20);
@@ -93,7 +93,7 @@ SUITE(CVStabilizer_Tests)
9393
c1.Open();
9494

9595
// Create first stabilizer
96-
CVStabilization stabilizer_1("{\"protobuf_data_path\": \"stabilizer.data\"}", processingController);
96+
CVStabilization stabilizer_1("{\"protobuf_data_path\": \"stabilizer.data\", \"smoothing_window\": 30}", processingController);
9797

9898
// Stabilize clip for frames 0-20
9999
stabilizer_1.stabilizeClip(c1, 0, 20+1, true);
@@ -106,7 +106,7 @@ SUITE(CVStabilizer_Tests)
106106
stabilizer_1.SaveStabilizedData();
107107

108108
// Create second stabilizer
109-
CVStabilization stabilizer_2("{\"protobuf_data_path\": \"stabilizer.data\"}", processingController);
109+
CVStabilization stabilizer_2("{\"protobuf_data_path\": \"stabilizer.data\", \"smoothing_window\": 30}", processingController);
110110

111111
// Load stabilized data from first stabilizer protobuf data
112112
stabilizer_2.LoadStabilizedData();

0 commit comments

Comments
 (0)