OpenShot Library | libopenshot  0.4.0
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 
23 using google::protobuf::util::TimeUtil;
24 
25 using namespace openshot;
26 
27 // Default Constructor, delegating
29  : TrackedObjectBBox::TrackedObjectBBox(0, 0, 255, 255) {}
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
33 TrackedObjectBBox::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
45 void 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
82 bool 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
96 bool 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
110 void 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
125 BBox 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
178 BBox TrackedObjectBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
179 {
180  // Interpolate the x-coordinate of the center point
181  Point cx_left(t1, left.cx, openshot::InterpolationType::LINEAR);
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
186  Point cy_left(t1, left.cy, openshot::InterpolationType::LINEAR);
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
223 double 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
230 void TrackedObjectBBox::ScalePoints(double time_scale){
231  this->TimeScale = time_scale;
232 }
233 
234 // Load the bounding-boxes information from the protobuf file
235 bool 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
300 std::string TrackedObjectBBox::Json() const
301 {
302  // Return formatted string
303  return JsonValue().toStyledString();
304 }
305 
306 // Generate Json::Value for this object
307 Json::Value TrackedObjectBBox::JsonValue() const
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
338 void 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
356 void 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)
413 Json::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
461 Json::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
498 std::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 }
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
openshot::TrackedObjectBBox::PropertiesJSON
Json::Value PropertiesJSON(int64_t requested_frame) const override
Definition: TrackedObjectBBox.cpp:413
openshot::TrackedObjectBBox::stroke_alpha
Keyframe stroke_alpha
Stroke box opacity.
Definition: TrackedObjectBBox.h:146
openshot::TrackedObjectBBox::rotation
Keyframe rotation
Rotation Keyframe.
Definition: TrackedObjectBBox.h:142
openshot::TrackedObjectBBox::AddBox
void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle) override
Add a BBox to the BoxVec map.
Definition: TrackedObjectBBox.cpp:45
openshot::Coordinate::Y
double Y
The Y value of the coordinate (usually representing the value of the property being animated)
Definition: Coordinate.h:41
Clip.h
Header file for Clip class.
openshot::BBox::height
float height
bounding box height
Definition: TrackedObjectBBox.h:42
openshot::TrackedObjectBBox::Contains
bool Contains(int64_t frame_number) const
Check if there is a bounding-box in the given frame.
Definition: TrackedObjectBBox.cpp:82
openshot::TrackedObjectBBox::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: TrackedObjectBBox.cpp:307
openshot::TrackedObjectBBox::background
Color background
Background fill color.
Definition: TrackedObjectBBox.h:148
openshot::TrackedObjectBBox::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: TrackedObjectBBox.cpp:356
openshot::Point::interpolation
InterpolationType interpolation
This is the interpolation mode.
Definition: Point.h:69
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::Point::co
Coordinate co
This is the primary coordinate.
Definition: Point.h:66
openshot::TrackedObjectBBox::add_property_json
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
Definition: TrackedObjectBBox.cpp:461
openshot::TrackedObjectBBox::FrameNToTime
double FrameNToTime(int64_t frame_number, double time_scale) const
Get the time of the given frame.
Definition: TrackedObjectBBox.cpp:223
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:30
openshot::BBox::cy
float cy
y-coordinate of the bounding box center
Definition: TrackedObjectBBox.h:40
openshot::TrackedObjectBBox::ScalePoints
void ScalePoints(double scale) override
Update the TimeScale member variable.
Definition: TrackedObjectBBox.cpp:230
openshot::Keyframe::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: KeyFrame.cpp:372
openshot::TrackedObjectBBox::Json
std::string Json() const override
Get and Set JSON methods.
Definition: TrackedObjectBBox.cpp:300
openshot::TrackedObjectBBox::GetBaseFPS
Fraction GetBaseFPS()
Return the object's BaseFps.
Definition: TrackedObjectBBox.cpp:218
openshot::TrackedObjectBase::add_property_choice_json
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
Definition: TrackedObjectBase.cpp:28
openshot::Keyframe::Contains
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition: KeyFrame.cpp:184
openshot::TrackedObjectBase::draw_box
Keyframe draw_box
Keyframe to determine if a specific box is drawn (or hidden)
Definition: TrackedObjectBase.h:46
openshot::TrackedObjectBase::Id
std::string Id() const
Get the id of this object.
Definition: TrackedObjectBase.h:58
openshot::Fraction::ToDouble
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:40
openshot::TrackedObjectBBox::scale_y
Keyframe scale_y
Y-direction scale Keyframe.
Definition: TrackedObjectBBox.h:141
openshot::Keyframe::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: KeyFrame.cpp:339
openshot::BBox::angle
float angle
bounding box rotation angle [degrees]
Definition: TrackedObjectBBox.h:43
openshot::Fraction::num
int num
Numerator for the fraction.
Definition: Fraction.h:32
openshot::TrackedObjectBase::visible
Keyframe visible
Keyframe to track if a box is visible in the current frame (read-only)
Definition: TrackedObjectBase.h:43
openshot::TrackedObjectBBox
This class contains the properties of a tracked object and functions to manipulate it.
Definition: TrackedObjectBBox.h:130
openshot::Fraction::den
int den
Denominator for the fraction.
Definition: Fraction.h:33
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
openshot::Color::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Color.cpp:117
openshot::Fraction::Reciprocal
Fraction Reciprocal() const
Return the reciprocal as a Fraction.
Definition: Fraction.cpp:78
openshot::InterpolateBetween
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
openshot::TrackedObjectBBox::scale_x
Keyframe scale_x
X-direction scale Keyframe.
Definition: TrackedObjectBBox.h:140
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:217
openshot::TrackedObjectBBox::GetBox
BBox GetBox(int64_t frame_number)
Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes.
Definition: TrackedObjectBBox.cpp:125
openshot::TrackedObjectBBox::TrackedObjectBBox
TrackedObjectBBox()
Default Constructor.
Definition: TrackedObjectBBox.cpp:28
openshot::BBox::width
float width
bounding box width
Definition: TrackedObjectBBox.h:41
openshot::Color::green
openshot::Keyframe green
Curve representing the green value (0 - 255)
Definition: Color.h:31
openshot::TrackedObjectBBox::InterpolateBoxes
BBox InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
Interpolate the bouding-boxes properties.
Definition: TrackedObjectBBox.cpp:178
openshot::TrackedObjectBBox::delta_y
Keyframe delta_y
Y-direction displacement Keyframe.
Definition: TrackedObjectBBox.h:139
openshot::TrackedObjectBBox::RemoveBox
void RemoveBox(int64_t frame_number)
Remove a bounding-box from the BoxVec map.
Definition: TrackedObjectBBox.cpp:110
openshot::TrackedObjectBBox::BoxVec
std::map< double, BBox > BoxVec
Index the bounding-box by time of each frame.
Definition: TrackedObjectBBox.h:137
openshot::TrackedObjectBBox::GetBoxValues
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.
Definition: TrackedObjectBBox.cpp:498
openshot::LINEAR
@ LINEAR
Linear curves are angular, straight lines between two points.
Definition: Point.h:30
openshot::Color::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Color.cpp:86
openshot::Keyframe::GetClosestPoint
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
openshot::TrackedObjectBBox::delta_x
Keyframe delta_x
X-direction displacement Keyframe.
Definition: TrackedObjectBBox.h:138
openshot::BBox
This struct holds the information of a bounding-box.
Definition: TrackedObjectBBox.h:37
openshot::TrackedObjectBBox::LoadBoxData
bool LoadBoxData(std::string inputFilePath)
Load the bounding-boxes information from the protobuf file.
Definition: TrackedObjectBBox.cpp:235
openshot::TrackedObjectBBox::clear
void clear()
Clear the BoxVec map.
Definition: TrackedObjectBBox.cpp:294
openshot::TrackedObjectBBox::SetBaseFPS
void SetBaseFPS(Fraction fps)
Update object's BaseFps.
Definition: TrackedObjectBBox.cpp:212
openshot::TrackedObjectBBox::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: TrackedObjectBBox.cpp:338
openshot::TrackedObjectBBox::stroke
Color stroke
Border line color.
Definition: TrackedObjectBBox.h:147
openshot::TrackedObjectBBox::ExactlyContains
bool ExactlyContains(int64_t frame_number) const override
Check if there is a bounding-box in the exact frame number.
Definition: TrackedObjectBBox.cpp:96
openshot::TrackedObjectBBox::protobufDataPath
std::string protobufDataPath
Path to the protobuf file that holds the bounding box points across the frames.
Definition: TrackedObjectBBox.h:150
openshot::Keyframe::GetCount
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition: KeyFrame.cpp:424
openshot::CONSTANT
@ CONSTANT
Constant curves jump from their previous position to a new one (with no interpolation).
Definition: Point.h:31
openshot::Keyframe::GetPreviousPoint
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition: KeyFrame.cpp:226
TrackedObjectBBox.h
Header file for the TrackedObjectBBox class.
openshot::BBox::cx
float cx
x-coordinate of the bounding box center
Definition: TrackedObjectBBox.h:39
openshot::TrackedObjectBBox::stroke_width
Keyframe stroke_width
Thickness of border line.
Definition: TrackedObjectBBox.h:145
openshot::Color::red
openshot::Keyframe red
Curve representing the red value (0 - 255)
Definition: Color.h:30
openshot::TrackedObjectBBox::background_corner
Keyframe background_corner
Radius of rounded corners.
Definition: TrackedObjectBBox.h:144
openshot::Point
A Point is the basic building block of a key-frame curve.
Definition: Point.h:64
openshot::Color::blue
openshot::Keyframe blue
Curve representing the red value (0 - 255)
Definition: Color.h:32
openshot::Coordinate::X
double X
The X value of the coordinate (usually representing the frame #)
Definition: Coordinate.h:40
openshot::Keyframe::GetValue
double GetValue(int64_t index) const
Get the value at a specific index.
Definition: KeyFrame.cpp:258
openshot::TrackedObjectBBox::background_alpha
Keyframe background_alpha
Background box opacity.
Definition: TrackedObjectBBox.h:143
openshot::TrackedObjectBBox::GetLength
int64_t GetLength() const
Get the size of BoxVec map.
Definition: TrackedObjectBBox.cpp:72