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