OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
TrackedObjectBBox.cpp
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#include <fstream>
15
16#include "TrackedObjectBBox.h"
17
18#include "Clip.h"
19
20#include "trackerdata.pb.h"
21#include <google/protobuf/util/time_util.h>
22
23using google::protobuf::util::TimeUtil;
24
25using namespace openshot;
26
27// Default Constructor, delegating
30
31// Constructor that takes RGBA values for stroke, and sets the bounding-box
32// displacement as 0 and the scales as 1 for the first frame
33TrackedObjectBBox::TrackedObjectBBox(int Red, int Green, int Blue, int Alfa)
34 : delta_x(0.0), delta_y(0.0),
35 scale_x(1.0), scale_y(1.0), rotation(0.0),
36 background_alpha(0.0), background_corner(12),
37 stroke_width(2) , stroke_alpha(0.7),
38 stroke(Red, Green, Blue, Alfa),
39 background(0, 0, 255, Alfa)
40{
41 this->TimeScale = 1.0;
42}
43
44// Add a BBox to the BoxVec map
45void TrackedObjectBBox::AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle)
46{
47 // Check if the given frame number is valid
48 if (_frame_num < 0)
49 return;
50
51 // Instantiate a new bounding-box
52 BBox newBBox = BBox(_cx, _cy, _width, _height, _angle);
53
54 // Get the time of given frame
55 double time = this->FrameNToTime(_frame_num, 1.0);
56 // Create an iterator that points to the BoxVec pair indexed by the time of given frame
57 auto BBoxIterator = BoxVec.find(time);
58
59 if (BBoxIterator != BoxVec.end())
60 {
61 // There is a bounding-box indexed by the time of given frame, update-it
62 BBoxIterator->second = newBBox;
63 }
64 else
65 {
66 // There isn't a bounding-box indexed by the time of given frame, insert a new one
67 BoxVec.insert({time, newBBox});
68 }
69}
70
71// Get the size of BoxVec map
73{
74 if (BoxVec.empty())
75 return 0;
76 if (BoxVec.size() == 1)
77 return 1;
78 return BoxVec.size();
79}
80
81// Check if there is a bounding-box in the given frame
82bool TrackedObjectBBox::Contains(int64_t frame_num) const
83{
84 // Get the time of given frame
85 double time = this->FrameNToTime(frame_num, 1.0);
86 // Create an iterator that points to the BoxVec pair indexed by the time of given frame (or the closest time)
87 auto it = BoxVec.lower_bound(time);
88 if (it == BoxVec.end()){
89 // BoxVec pair not found
90 return false;
91 }
92 return true;
93}
94
95// Check if there is a bounding-box in the exact frame number
96bool TrackedObjectBBox::ExactlyContains(int64_t frame_number) const
97{
98 // Get the time of given frame
99 double time = FrameNToTime(frame_number, 1.0);
100 // Create an iterator that points to the BoxVec pair indexed by the exact time of given frame
101 auto it = BoxVec.find(time);
102 if (it == BoxVec.end()){
103 // BoxVec pair not found
104 return false;
105 }
106 return true;
107}
108
109// Remove a bounding-box from the BoxVec map
110void TrackedObjectBBox::RemoveBox(int64_t frame_number)
111{
112 // Get the time of given frame
113 double time = this->FrameNToTime(frame_number, 1.0);
114 // Create an iterator that points to the BoxVec pair indexed by the time of given frame
115 auto it = BoxVec.find(time);
116 if (it != BoxVec.end())
117 {
118 // The BoxVec pair exists, so remove it
119 BoxVec.erase(time);
120 }
121 return;
122}
123
124// Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes
125BBox TrackedObjectBBox::GetBox(int64_t frame_number)
126{
127 // Get the time position of the given frame.
128 double time = this->FrameNToTime(frame_number, this->TimeScale);
129
130 // Return a iterator pointing to the BoxVec pair indexed by time or to the pair indexed
131 // by the closest upper time value.
132 auto currentBBoxIterator = BoxVec.lower_bound(time);
133
134 // Check if there is a pair indexed by time, returns an empty bbox if there isn't.
135 if (currentBBoxIterator == BoxVec.end())
136 {
137 // Create and return an empty bounding-box object
138 BBox emptyBBox;
139 return emptyBBox;
140 }
141
142 // Check if the iterator matches a BBox indexed by time or points to the first element of BoxVec
143 if ((currentBBoxIterator->first == time) || (currentBBoxIterator == BoxVec.begin()))
144 {
145 // Get the BBox indexed by time
146 BBox currentBBox = currentBBoxIterator->second;
147
148 // Adjust the BBox properties by the Keyframes values
149 currentBBox.cx += this->delta_x.GetValue(frame_number);
150 currentBBox.cy += this->delta_y.GetValue(frame_number);
151 currentBBox.width *= this->scale_x.GetValue(frame_number);
152 currentBBox.height *= this->scale_y.GetValue(frame_number);
153 currentBBox.angle += this->rotation.GetValue(frame_number);
154
155 return currentBBox;
156 }
157
158 // BBox indexed by the closest upper time
159 BBox currentBBox = currentBBoxIterator->second;
160 // BBox indexed by the closet lower time
161 BBox previousBBox = prev(currentBBoxIterator, 1)->second;
162
163 // Interpolate a BBox in the middle of previousBBox and currentBBox
164 BBox interpolatedBBox = InterpolateBoxes(prev(currentBBoxIterator, 1)->first, currentBBoxIterator->first,
165 previousBBox, currentBBox, time);
166
167 // Adjust the BBox properties by the Keyframes values
168 interpolatedBBox.cx += this->delta_x.GetValue(frame_number);
169 interpolatedBBox.cy += this->delta_y.GetValue(frame_number);
170 interpolatedBBox.width *= this->scale_x.GetValue(frame_number);
171 interpolatedBBox.height *= this->scale_y.GetValue(frame_number);
172 interpolatedBBox.angle += this->rotation.GetValue(frame_number);
173
174 return interpolatedBBox;
175}
176
177// Interpolate the bouding-boxes properties
178BBox TrackedObjectBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
179{
180 // Interpolate the x-coordinate of the center point
182 Point cx_right(t2, right.cx, openshot::InterpolationType::LINEAR);
183 Point cx = InterpolateBetween(cx_left, cx_right, target, 0.01);
184
185 // Interpolate de y-coordinate of the center point
187 Point cy_right(t2, right.cy, openshot::InterpolationType::LINEAR);
188 Point cy = InterpolateBetween(cy_left, cy_right, target, 0.01);
189
190 // Interpolate the width
191 Point width_left(t1, left.width, openshot::InterpolationType::LINEAR);
192 Point width_right(t2, right.width, openshot::InterpolationType::LINEAR);
193 Point width = InterpolateBetween(width_left, width_right, target, 0.01);
194
195 // Interpolate the height
196 Point height_left(t1, left.height, openshot::InterpolationType::LINEAR);
197 Point height_right(t2, right.height, openshot::InterpolationType::LINEAR);
198 Point height = InterpolateBetween(height_left, height_right, target, 0.01);
199
200 // Interpolate the rotation angle
201 Point angle_left(t1, left.angle, openshot::InterpolationType::LINEAR);
202 Point angle_right(t1, right.angle, openshot::InterpolationType::LINEAR);
203 Point angle = InterpolateBetween(angle_left, angle_right, target, 0.01);
204
205 // Create a bounding box with the interpolated points
206 BBox interpolatedBox(cx.co.Y, cy.co.Y, width.co.Y, height.co.Y, angle.co.Y);
207
208 return interpolatedBox;
209}
210
211// Update object's BaseFps
213 this->BaseFps = fps;
214 return;
215}
216
217// Return the object's BaseFps
219 return BaseFps;
220}
221
222// Get the time of the given frame
223double TrackedObjectBBox::FrameNToTime(int64_t frame_number, double time_scale) const{
224 double time = ((double)frame_number) * this->BaseFps.Reciprocal().ToDouble() * (1.0 / time_scale);
225
226 return time;
227}
228
229// Update the TimeScale member variable
230void TrackedObjectBBox::ScalePoints(double time_scale){
231 this->TimeScale = time_scale;
232}
233
234// Load the bounding-boxes information from the protobuf file
235bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
236{
237 using std::ios;
238
239 // Variable to hold the loaded data
240 pb_tracker::Tracker bboxMessage;
241
242 // Read the existing tracker message.
243 std::fstream input(inputFilePath, ios::in | ios::binary);
244
245 // Check if it was able to read the protobuf data
246 if (!bboxMessage.ParseFromIstream(&input))
247 {
248 std::cerr << "Failed to parse protobuf message." << std::endl;
249 return false;
250 }
251
252 this->clear();
253
254 // Iterate over all frames of the saved message
255 for (size_t i = 0; i < bboxMessage.frame_size(); i++)
256 {
257 // Get data of the i-th frame
258 const pb_tracker::Frame &pbFrameData = bboxMessage.frame(i);
259
260 // Get frame number
261 size_t frame_number = pbFrameData.id();
262
263 // Get bounding box data from current frame
264 const pb_tracker::Frame::Box &box = pbFrameData.bounding_box();
265
266 float width = box.x2() - box.x1();
267 float height = box.y2() - box.y1();
268 float cx = box.x1() + width/2;
269 float cy = box.y1() + height/2;
270 float angle = 0.0;
271
272
273 if ( (cx >= 0.0) && (cy >= 0.0) && (width >= 0.0) && (height >= 0.0) )
274 {
275 // The bounding-box properties are valid, so add it to the BoxVec map
276 this->AddBox(frame_number, cx, cy, width, height, angle);
277 }
278 }
279
280 // Show the time stamp from the last update in tracker data file
281 if (bboxMessage.has_last_updated())
282 {
283 std::cout << " Loaded Data. Saved Time Stamp: "
284 << TimeUtil::ToString(bboxMessage.last_updated()) << std::endl;
285 }
286
287 // Delete all global objects allocated by libprotobuf.
288 google::protobuf::ShutdownProtobufLibrary();
289
290 return true;
291}
292
293// Clear the BoxVec map
295{
296 BoxVec.clear();
297}
298
299// Generate JSON string of this object
300std::string TrackedObjectBBox::Json() const
301{
302 // Return formatted string
303 return JsonValue().toStyledString();
304}
305
306// Generate Json::Value for this object
308{
309 // Create root json object
310 Json::Value root;
311
312 // Object's properties
313 root["box_id"] = Id();
314 root["BaseFPS"]["num"] = BaseFps.num;
315 root["BaseFPS"]["den"] = BaseFps.den;
316 root["TimeScale"] = TimeScale;
317
318 // Keyframe's properties
319 root["delta_x"] = delta_x.JsonValue();
320 root["delta_y"] = delta_y.JsonValue();
321 root["scale_x"] = scale_x.JsonValue();
322 root["scale_y"] = scale_y.JsonValue();
323 root["rotation"] = rotation.JsonValue();
324 root["visible"] = visible.JsonValue();
325 root["draw_box"] = draw_box.JsonValue();
326 root["stroke"] = stroke.JsonValue();
327 root["background_alpha"] = background_alpha.JsonValue();
328 root["background_corner"] = background_corner.JsonValue();
329 root["background"] = background.JsonValue();
330 root["stroke_width"] = stroke_width.JsonValue();
331 root["stroke_alpha"] = stroke_alpha.JsonValue();
332
333 // return JsonValue
334 return root;
335}
336
337// Load JSON string into this object
338void TrackedObjectBBox::SetJson(const std::string value)
339{
340 // Parse JSON string into JSON objects
341 try
342 {
343 const Json::Value root = openshot::stringToJson(value);
344 // Set all values that match
345 SetJsonValue(root);
346 }
347 catch (const std::exception &e)
348 {
349 // Error parsing JSON (or missing keys)
350 throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
351 }
352 return;
353}
354
355// Load Json::Value into this object
356void TrackedObjectBBox::SetJsonValue(const Json::Value root)
357{
358
359 // Set the Id by the given JSON object
360 if (!root["box_id"].isNull() && root["box_id"].asString() != "")
361 Id(root["box_id"].asString());
362
363 // Set the BaseFps by the given JSON object
364 if (!root["BaseFPS"].isNull() && root["BaseFPS"].isObject())
365 {
366 if (!root["BaseFPS"]["num"].isNull())
367 BaseFps.num = (int)root["BaseFPS"]["num"].asInt();
368 if (!root["BaseFPS"]["den"].isNull())
369 BaseFps.den = (int)root["BaseFPS"]["den"].asInt();
370 }
371 // Set the TimeScale by the given JSON object
372 if (!root["TimeScale"].isNull())
373 {
374 double scale = (double)root["TimeScale"].asDouble();
375 this->ScalePoints(scale);
376 }
377 // Set the protobuf data path by the given JSON object
378 if (!root["protobuf_data_path"].isNull())
379 protobufDataPath = root["protobuf_data_path"].asString();
380
381 // Set the Keyframes by the given JSON object
382 if (!root["delta_x"].isNull())
383 delta_x.SetJsonValue(root["delta_x"]);
384 if (!root["delta_y"].isNull())
385 delta_y.SetJsonValue(root["delta_y"]);
386 if (!root["scale_x"].isNull())
387 scale_x.SetJsonValue(root["scale_x"]);
388 if (!root["scale_y"].isNull())
389 scale_y.SetJsonValue(root["scale_y"]);
390 if (!root["rotation"].isNull())
391 rotation.SetJsonValue(root["rotation"]);
392 if (!root["visible"].isNull())
393 visible.SetJsonValue(root["visible"]);
394 if (!root["draw_box"].isNull())
395 draw_box.SetJsonValue(root["draw_box"]);
396 if (!root["stroke"].isNull())
397 stroke.SetJsonValue(root["stroke"]);
398 if (!root["background_alpha"].isNull())
399 background_alpha.SetJsonValue(root["background_alpha"]);
400 if (!root["background_corner"].isNull())
401 background_corner.SetJsonValue(root["background_corner"]);
402 if (!root["background"].isNull())
403 background.SetJsonValue(root["background"]);
404 if (!root["stroke_width"].isNull())
405 stroke_width.SetJsonValue(root["stroke_width"]);
406 if (!root["stroke_alpha"].isNull())
407 stroke_alpha.SetJsonValue(root["stroke_alpha"]);
408 return;
409}
410
411// Get all properties for a specific frame (perfect for a UI to display the current state
412// of all properties at any time)
413Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const
414{
415 Json::Value root;
416
417 BBox box = GetBox(requested_frame);
418
419 // Add the ID of this object to the JSON object
420 root["box_id"] = add_property_json("Box ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
421
422 // Add the data of given frame bounding-box to the JSON object
423 root["x1"] = add_property_json("X1", box.cx-(box.width/2), "float", "", NULL, 0.0, 1.0, true, requested_frame);
424 root["y1"] = add_property_json("Y1", box.cy-(box.height/2), "float", "", NULL, 0.0, 1.0, true, requested_frame);
425 root["x2"] = add_property_json("X2", box.cx+(box.width/2), "float", "", NULL, 0.0, 1.0, true, requested_frame);
426 root["y2"] = add_property_json("Y2", box.cy+(box.height/2), "float", "", NULL, 0.0, 1.0, true, requested_frame);
427
428 // Add the bounding-box Keyframes to the JSON object
429 root["delta_x"] = add_property_json("Displacement X-axis", delta_x.GetValue(requested_frame), "float", "", &delta_x, -1.0, 1.0, false, requested_frame);
430 root["delta_y"] = add_property_json("Displacement Y-axis", delta_y.GetValue(requested_frame), "float", "", &delta_y, -1.0, 1.0, false, requested_frame);
431 root["scale_x"] = add_property_json("Scale (Width)", scale_x.GetValue(requested_frame), "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
432 root["scale_y"] = add_property_json("Scale (Height)", scale_y.GetValue(requested_frame), "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
433 root["rotation"] = add_property_json("Rotation", rotation.GetValue(requested_frame), "float", "", &rotation, 0, 360, false, requested_frame);
434 root["visible"] = add_property_json("Visible", visible.GetValue(requested_frame), "int", "", &visible, 0, 1, true, requested_frame);
435
436 root["draw_box"] = add_property_json("Draw Box", draw_box.GetValue(requested_frame), "int", "", &draw_box, 0, 1, false, requested_frame);
437 root["draw_box"]["choices"].append(add_property_choice_json("Yes", true, draw_box.GetValue(requested_frame)));
438 root["draw_box"]["choices"].append(add_property_choice_json("No", false, draw_box.GetValue(requested_frame)));
439
440 root["stroke"] = add_property_json("Border", 0.0, "color", "", NULL, 0, 255, false, requested_frame);
441 root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
442 root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
443 root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
444 root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "int", "", &stroke_width, 1, 10, false, requested_frame);
445 root["stroke_alpha"] = add_property_json("Stroke alpha", stroke_alpha.GetValue(requested_frame), "float", "", &stroke_alpha, 0.0, 1.0, false, requested_frame);
446
447 root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
448 root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "int", "", &background_corner, 0.0, 150.0, false, requested_frame);
449
450 root["background"] = add_property_json("Background", 0.0, "color", "", NULL, 0, 255, false, requested_frame);
451 root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
452 root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
453 root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
454
455 // Return formatted string
456 return root;
457}
458
459
460// Generate JSON for a property
461Json::Value TrackedObjectBBox::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 {
462
463 // Requested Point
464 const Point requested_point(requested_frame, requested_frame);
465
466 // Create JSON Object
467 Json::Value prop = Json::Value(Json::objectValue);
468 prop["name"] = name;
469 prop["value"] = value;
470 prop["memo"] = memo;
471 prop["type"] = type;
472 prop["min"] = min_value;
473 prop["max"] = max_value;
474 if (keyframe) {
475 prop["keyframe"] = keyframe->Contains(requested_point);
476 prop["points"] = int(keyframe->GetCount());
477 Point closest_point = keyframe->GetClosestPoint(requested_point);
478 prop["interpolation"] = closest_point.interpolation;
479 prop["closest_point_x"] = closest_point.co.X;
480 prop["previous_point_x"] = keyframe->GetPreviousPoint(closest_point).co.X;
481 }
482 else {
483 prop["keyframe"] = false;
484 prop["points"] = 0;
485 prop["interpolation"] = CONSTANT;
486 prop["closest_point_x"] = -1;
487 prop["previous_point_x"] = -1;
488 }
489
490 prop["readonly"] = readonly;
491 prop["choices"] = Json::Value(Json::arrayValue);
492
493 // return JsonValue
494 return prop;
495}
496
497// Return a map that contains the bounding box properties and it's keyframes indexed by their names
498std::map<std::string, float> TrackedObjectBBox::GetBoxValues(int64_t frame_number) const {
499
500 // Create the map
501 std::map<std::string, float> boxValues;
502
503 // Get bounding box of the current frame
504 BBox box = GetBox(frame_number);
505
506 // Save the bounding box properties
507 boxValues["cx"] = box.cx;
508 boxValues["cy"] = box.cy;
509 boxValues["w"] = box.width;
510 boxValues["h"] = box.height;
511 boxValues["ang"] = box.angle;
512
513 // Save the keyframes values
514 boxValues["sx"] = this->scale_x.GetValue(frame_number);
515 boxValues["sy"] = this->scale_y.GetValue(frame_number);
516 boxValues["dx"] = this->delta_x.GetValue(frame_number);
517 boxValues["dy"] = this->delta_y.GetValue(frame_number);
518 boxValues["r"] = this->rotation.GetValue(frame_number);
519
520
521 return boxValues;
522}
Header file for Clip class.
Header file for the TrackedObjectBBox class.
openshot::Keyframe blue
Curve representing the red value (0 - 255)
Definition Color.h:32
openshot::Keyframe red
Curve representing the red value (0 - 255)
Definition Color.h:30
openshot::Keyframe green
Curve representing the green value (0 - 255)
Definition Color.h:31
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition Color.cpp:117
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition Color.cpp:86
double X
The X value of the coordinate (usually representing the frame #)
Definition Coordinate.h:40
double Y
The Y value of the coordinate (usually representing the value of the property being animated)
Definition Coordinate.h:41
This class represents a fraction.
Definition Fraction.h:30
int num
Numerator for the fraction.
Definition Fraction.h:32
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition Fraction.cpp:40
Fraction Reciprocal() const
Return the reciprocal as a Fraction.
Definition Fraction.cpp:78
int den
Denominator for the fraction.
Definition Fraction.h:33
Exception for invalid JSON.
Definition Exceptions.h:218
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition KeyFrame.h:53
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition KeyFrame.cpp:184
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition KeyFrame.cpp:372
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition KeyFrame.cpp:226
double GetValue(int64_t index) const
Get the value at a specific index.
Definition KeyFrame.cpp:258
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition KeyFrame.cpp:339
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition KeyFrame.cpp:424
Point GetClosestPoint(Point p) const
Get current point (or closest point to the right) from the X coordinate (i.e. the frame number)
Definition KeyFrame.cpp:221
A Point is the basic building block of a key-frame curve.
Definition Point.h:64
Coordinate co
This is the primary coordinate.
Definition Point.h:66
InterpolationType interpolation
This is the interpolation mode.
Definition Point.h:69
This class contains the properties of a tracked object and functions to manipulate it.
Keyframe delta_x
X-direction displacement Keyframe.
bool LoadBoxData(std::string inputFilePath)
Load the bounding-boxes information from the protobuf file.
Color stroke
Border line color.
Keyframe rotation
Rotation Keyframe.
int64_t GetLength() const
Get the size of BoxVec map.
Keyframe stroke_width
Thickness of border line.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle) override
Add a BBox to the BoxVec map.
TrackedObjectBBox()
Default Constructor.
void SetBaseFPS(Fraction fps)
Update object's BaseFps.
void SetJson(const std::string value) override
Load JSON string into this object.
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
void clear()
Clear the BoxVec map.
Keyframe delta_y
Y-direction displacement Keyframe.
Color background
Background fill color.
std::map< double, BBox > BoxVec
Index the bounding-box by time of each frame.
std::string Json() const override
Get and Set JSON methods.
bool ExactlyContains(int64_t frame_number) const override
Check if there is a bounding-box in the exact frame number.
void ScalePoints(double scale) override
Update the TimeScale member variable.
BBox InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
Interpolate the bouding-boxes properties.
Fraction GetBaseFPS()
Return the object's BaseFps.
Json::Value PropertiesJSON(int64_t requested_frame) const override
Keyframe background_alpha
Background box opacity.
void RemoveBox(int64_t frame_number)
Remove a bounding-box from the BoxVec map.
bool Contains(int64_t frame_number) const
Check if there is a bounding-box in the given frame.
std::map< std::string, float > GetBoxValues(int64_t frame_number) const override
Return a map that contains the bounding box properties and it's keyframes indexed by their names.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe scale_y
Y-direction scale Keyframe.
std::string protobufDataPath
Path to the protobuf file that holds the bounding box points across the frames.
Keyframe stroke_alpha
Stroke box opacity.
double FrameNToTime(int64_t frame_number, double time_scale) const
Get the time of the given frame.
Keyframe scale_x
X-direction scale Keyframe.
BBox GetBox(int64_t frame_number)
Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes.
Keyframe background_corner
Radius of rounded corners.
Keyframe draw_box
Keyframe to determine if a specific box is drawn (or hidden)
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
Keyframe visible
Keyframe to track if a box is visible in the current frame (read-only)
std::string Id() const
Get the id of this object.
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
double InterpolateBetween(Point const &left, Point const &right, double target, double allowed_error)
Interpolate two points using the right Point's interpolation method.
Definition KeyFrame.cpp:80
const Json::Value stringToJson(const std::string value)
Definition Json.cpp:16
@ CONSTANT
Constant curves jump from their previous position to a new one (with no interpolation).
Definition Point.h:31
@ LINEAR
Linear curves are angular, straight lines between two points.
Definition Point.h:30
This struct holds the information of a bounding-box.
float cy
y-coordinate of the bounding box center
float height
bounding box height
float cx
x-coordinate of the bounding box center
float width
bounding box width
float angle
bounding box rotation angle [degrees]