OpenShot Library | libopenshot  0.3.1
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, 0) {}
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),
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
46 void 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
83 bool 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
97 bool 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
111 void 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
126 BBox 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
179 BBox TrackedObjectBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
180 {
181  // Interpolate the x-coordinate of the center point
182  Point cx_left(t1, left.cx, openshot::InterpolationType::LINEAR);
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
187  Point cy_left(t1, left.cy, openshot::InterpolationType::LINEAR);
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
224 double 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
231 void TrackedObjectBBox::ScalePoints(double time_scale){
232  this->TimeScale = time_scale;
233 }
234 
235 // Load the bounding-boxes information from the protobuf file
236 bool 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
301 std::string TrackedObjectBBox::Json() const
302 {
303  // Return formatted string
304  return JsonValue().toStyledString();
305 }
306 
307 // Generate Json::Value for this object
308 Json::Value TrackedObjectBBox::JsonValue() const
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
340 void 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
358 void 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() != "" && root["child_clip_id"].asString() != Id()){
385  Clip* parentClip = (Clip *) ParentClip();
386 
387  if (root["child_clip_id"].asString() != parentClip->Id())
388  ChildClipId(root["child_clip_id"].asString());
389  }
390 
391  // Set the Keyframes by the given JSON object
392  if (!root["delta_x"].isNull())
393  delta_x.SetJsonValue(root["delta_x"]);
394  if (!root["delta_y"].isNull())
395  delta_y.SetJsonValue(root["delta_y"]);
396  if (!root["scale_x"].isNull())
397  scale_x.SetJsonValue(root["scale_x"]);
398  if (!root["scale_y"].isNull())
399  scale_y.SetJsonValue(root["scale_y"]);
400  if (!root["rotation"].isNull())
401  rotation.SetJsonValue(root["rotation"]);
402  if (!root["visible"].isNull())
403  visible.SetJsonValue(root["visible"]);
404  if (!root["draw_box"].isNull())
405  draw_box.SetJsonValue(root["draw_box"]);
406  if (!root["stroke"].isNull())
407  stroke.SetJsonValue(root["stroke"]);
408  if (!root["background_alpha"].isNull())
409  background_alpha.SetJsonValue(root["background_alpha"]);
410  if (!root["background_corner"].isNull())
411  background_corner.SetJsonValue(root["background_corner"]);
412  if (!root["background"].isNull())
413  background.SetJsonValue(root["background"]);
414  if (!root["stroke_width"].isNull())
415  stroke_width.SetJsonValue(root["stroke_width"]);
416  if (!root["stroke_alpha"].isNull())
417  stroke_alpha.SetJsonValue(root["stroke_alpha"]);
418  return;
419 }
420 
421 // Get all properties for a specific frame (perfect for a UI to display the current state
422 // of all properties at any time)
423 Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const
424 {
425  Json::Value root;
426 
427  BBox box = GetBox(requested_frame);
428 
429  // Add the ID of this object to the JSON object
430  root["box_id"] = add_property_json("Box ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
431 
432  // Add the ID of this object's child clip to the JSON object
433  root["child_clip_id"] = add_property_json("Child Clip ID", 0.0, "string", ChildClipId(), NULL, -1, -1, false, requested_frame);
434 
435  // Add the data of given frame bounding-box to the JSON object
436  root["x1"] = add_property_json("X1", box.cx-(box.width/2), "float", "", NULL, 0.0, 1.0, false, requested_frame);
437  root["y1"] = add_property_json("Y1", box.cy-(box.height/2), "float", "", NULL, 0.0, 1.0, false, requested_frame);
438  root["x2"] = add_property_json("X2", box.cx+(box.width/2), "float", "", NULL, 0.0, 1.0, false, requested_frame);
439  root["y2"] = add_property_json("Y2", box.cy+(box.height/2), "float", "", NULL, 0.0, 1.0, false, requested_frame);
440 
441  // Add the bounding-box Keyframes to the JSON object
442  root["delta_x"] = add_property_json("Displacement X-axis", delta_x.GetValue(requested_frame), "float", "", &delta_x, -1.0, 1.0, false, requested_frame);
443  root["delta_y"] = add_property_json("Displacement Y-axis", delta_y.GetValue(requested_frame), "float", "", &delta_y, -1.0, 1.0, false, requested_frame);
444  root["scale_x"] = add_property_json("Scale (Width)", scale_x.GetValue(requested_frame), "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
445  root["scale_y"] = add_property_json("Scale (Height)", scale_y.GetValue(requested_frame), "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
446  root["rotation"] = add_property_json("Rotation", rotation.GetValue(requested_frame), "float", "", &rotation, 0, 360, false, requested_frame);
447  root["visible"] = add_property_json("Visible", visible.GetValue(requested_frame), "int", "", &visible, 0, 1, false, requested_frame);
448 
449  root["draw_box"] = add_property_json("Draw Box", draw_box.GetValue(requested_frame), "int", "", &draw_box, -1, 1.0, false, requested_frame);
450  root["draw_box"]["choices"].append(add_property_choice_json("Off", 0, draw_box.GetValue(requested_frame)));
451  root["draw_box"]["choices"].append(add_property_choice_json("On", 1, draw_box.GetValue(requested_frame)));
452 
453  root["stroke"] = add_property_json("Border", 0.0, "color", "", NULL, 0, 255, false, requested_frame);
454  root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
455  root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
456  root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
457  root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "int", "", &stroke_width, 1, 10, false, requested_frame);
458  root["stroke_alpha"] = add_property_json("Stroke alpha", stroke_alpha.GetValue(requested_frame), "float", "", &stroke_alpha, 0.0, 1.0, false, requested_frame);
459 
460  root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
461  root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "int", "", &background_corner, 0.0, 60.0, false, requested_frame);
462 
463  root["background"] = add_property_json("Background", 0.0, "color", "", NULL, 0, 255, false, requested_frame);
464  root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
465  root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
466  root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
467 
468  // Return formatted string
469  return root;
470 }
471 
472 
473 // Generate JSON for a property
474 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 {
475 
476  // Requested Point
477  const Point requested_point(requested_frame, requested_frame);
478 
479  // Create JSON Object
480  Json::Value prop = Json::Value(Json::objectValue);
481  prop["name"] = name;
482  prop["value"] = value;
483  prop["memo"] = memo;
484  prop["type"] = type;
485  prop["min"] = min_value;
486  prop["max"] = max_value;
487  if (keyframe) {
488  prop["keyframe"] = keyframe->Contains(requested_point);
489  prop["points"] = int(keyframe->GetCount());
490  Point closest_point = keyframe->GetClosestPoint(requested_point);
491  prop["interpolation"] = closest_point.interpolation;
492  prop["closest_point_x"] = closest_point.co.X;
493  prop["previous_point_x"] = keyframe->GetPreviousPoint(closest_point).co.X;
494  }
495  else {
496  prop["keyframe"] = false;
497  prop["points"] = 0;
498  prop["interpolation"] = CONSTANT;
499  prop["closest_point_x"] = -1;
500  prop["previous_point_x"] = -1;
501  }
502 
503  prop["readonly"] = readonly;
504  prop["choices"] = Json::Value(Json::arrayValue);
505 
506  // return JsonValue
507  return prop;
508 }
509 
510 // Return a map that contains the bounding box properties and it's keyframes indexed by their names
511 std::map<std::string, float> TrackedObjectBBox::GetBoxValues(int64_t frame_number) const {
512 
513  // Create the map
514  std::map<std::string, float> boxValues;
515 
516  // Get bounding box of the current frame
517  BBox box = GetBox(frame_number);
518 
519  // Save the bounding box properties
520  boxValues["cx"] = box.cx;
521  boxValues["cy"] = box.cy;
522  boxValues["w"] = box.width;
523  boxValues["h"] = box.height;
524  boxValues["ang"] = box.angle;
525 
526  // Save the keyframes values
527  boxValues["sx"] = this->scale_x.GetValue(frame_number);
528  boxValues["sy"] = this->scale_y.GetValue(frame_number);
529  boxValues["dx"] = this->delta_x.GetValue(frame_number);
530  boxValues["dy"] = this->delta_y.GetValue(frame_number);
531  boxValues["r"] = this->rotation.GetValue(frame_number);
532 
533 
534  return boxValues;
535 }
536 
537 // Return a map that contains the properties of this object's parent clip
538 std::map<std::string, float> TrackedObjectBBox::GetParentClipProperties(int64_t frame_number) const {
539 
540  // Get the parent clip of this object as a Clip pointer
541  Clip* parentClip = (Clip *) ParentClip();
542 
543  // Calculate parentClip's frame number
544  long parentClip_start_position = round( parentClip->Position() * parentClip->info.fps.ToDouble() ) + 1;
545  long parentClip_start_frame = ( parentClip->Start() * parentClip->info.fps.ToDouble() ) + 1;
546  float parentClip_frame_number = round(frame_number - parentClip_start_position) + parentClip_start_frame;
547 
548  // Get parentClip's Keyframes
549  float parentClip_location_x = parentClip->location_x.GetValue(parentClip_frame_number);
550  float parentClip_location_y = parentClip->location_y.GetValue(parentClip_frame_number);
551  float parentClip_scale_x = parentClip->scale_x.GetValue(parentClip_frame_number);
552  float parentClip_scale_y = parentClip->scale_y.GetValue(parentClip_frame_number);
553  float parentClip_rotation = parentClip->rotation.GetValue(parentClip_frame_number);
554 
555  // Initialize the parent clip properties map
556  std::map<std::string, float> parentClipProperties;
557 
558  // Set the map properties
559  parentClipProperties["frame_number"] = parentClip_frame_number;
560  parentClipProperties["timeline_frame_number"] = frame_number;
561  parentClipProperties["location_x"] = parentClip_location_x;
562  parentClipProperties["location_y"] = parentClip_location_y;
563  parentClipProperties["scale_x"] = parentClip_scale_x;
564  parentClipProperties["scale_y"] = parentClip_scale_y;
565  parentClipProperties["rotation"] = parentClip_rotation;
566 
567  return parentClipProperties;
568 }
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Color.cpp:117
int num
Numerator for the fraction.
Definition: Fraction.h:32
bool ExactlyContains(int64_t frame_number) const override
Check if there is a bounding-box in the exact frame number.
Json::Value PropertiesJSON(int64_t requested_frame) const override
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::string Id() const
Get the Id of this clip object.
Definition: ClipBase.h:85
void clear()
Clear the BoxVec map.
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:88
float cy
y-coordinate of the bounding box center
ClipBase * ParentClip() const
Get and set the parentClip of this object.
Keyframe background_alpha
Background box opacity.
InterpolationType interpolation
This is the interpolation mode.
Definition: Point.h:69
openshot::Keyframe location_y
Curve representing the relative Y position in percent based on the gravity (-1 to 1) ...
Definition: Clip.h:303
float height
bounding box height
Keyframe stroke_alpha
Stroke box opacity.
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
void SetBaseFPS(Fraction fps)
Update object&#39;s BaseFps.
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:40
Keyframe delta_y
Y-direction displacement Keyframe.
A Point is the basic building block of a key-frame curve.
Definition: Point.h:64
std::map< std::string, float > GetParentClipProperties(int64_t frame_number) const override
Return a map that contains the properties of this object&#39;s parent clip.
openshot::Keyframe scale_x
Curve representing the horizontal scaling in percent (0 to 1)
Definition: Clip.h:300
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition: KeyFrame.cpp:226
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
openshot::Keyframe scale_y
Curve representing the vertical scaling in percent (0 to 1)
Definition: Clip.h:301
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition: KeyFrame.cpp:184
float angle
bounding box rotation angle [degrees]
openshot::Keyframe blue
Curve representing the red value (0 - 255)
Definition: Color.h:32
Keyframe stroke_width
Thickness of border line.
Color background
Background fill color.
std::string protobufDataPath
Path to the protobuf file that holds the bounding box points across the frames.
Color stroke
Border line color.
bool LoadBoxData(std::string inputFilePath)
Load the bounding-boxes information from the protobuf file.
BBox InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
Interpolate the bouding-boxes properties.
This class represents a clip (used to arrange readers on the timeline)
Definition: Clip.h:91
double Y
The Y value of the coordinate (usually representing the value of the property being animated) ...
Definition: Coordinate.h:41
Keyframe delta_x
X-direction displacement Keyframe.
openshot::Keyframe green
Curve representing the green value (0 - 255)
Definition: Color.h:31
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
BBox GetBox(int64_t frame_number)
Return a bounding-box from BoxVec with it&#39;s properties adjusted by the Keyframes. ...
openshot::Keyframe rotation
Curve representing the rotation (0 to 360)
Definition: Clip.h:307
Header file for Clip class.
float width
bounding box width
This class represents a fraction.
Definition: Fraction.h:30
std::map< std::string, float > GetBoxValues(int64_t frame_number) const override
Return a map that contains the bounding box properties and it&#39;s keyframes indexed by their names...
Fraction GetBaseFPS()
Return the object&#39;s BaseFps.
double InterpolateBetween(Point const &left, Point const &right, double target, double allowed_error)
Interpolate two points using the right Point&#39;s interpolation method.
Definition: KeyFrame.cpp:80
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
double FrameNToTime(int64_t frame_number, double time_scale) const
Get the time of the given frame.
void RemoveBox(int64_t frame_number)
Remove a bounding-box from the BoxVec map.
Fraction Reciprocal() const
Return the reciprocal as a Fraction.
Definition: Fraction.cpp:78
std::map< double, BBox > BoxVec
Index the bounding-box by time of each frame.
double X
The X value of the coordinate (usually representing the frame #)
Definition: Coordinate.h:40
void SetJson(const std::string value) override
Load JSON string into this object.
This struct holds the information of a bounding-box.
Keyframe scale_y
Y-direction scale Keyframe.
TrackedObjectBBox()
Default Constructor.
void ScalePoints(double scale) override
Update the TimeScale member variable.
openshot::ReaderInfo info
Information about the current media file.
Definition: ReaderBase.h:88
Header file for the TrackedObjectBBox class.
int64_t GetLength() const
Get the size of BoxVec map.
std::string ChildClipId() const
Get and set the Id of the childClip of this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: KeyFrame.cpp:372
Keyframe rotation
Rotation Keyframe.
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
Keyframe scale_x
X-direction scale Keyframe.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
float cx
x-coordinate of the bounding box center
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: KeyFrame.cpp:339
Linear curves are angular, straight lines between two points.
Definition: Point.h:30
Coordinate co
This is the primary coordinate.
Definition: Point.h:66
Exception for invalid JSON.
Definition: Exceptions.h:217
std::string Id() const
Get the id of this object.
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition: KeyFrame.cpp:417
double GetValue(int64_t index) const
Get the value at a specific index.
Definition: KeyFrame.cpp:258
void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle) override
Add a BBox to the BoxVec map.
openshot::Keyframe red
Curve representing the red value (0 - 255)
Definition: Color.h:30
bool Contains(int64_t frame_number) const
Check if there is a bounding-box in the given frame.
openshot::Keyframe location_x
Curve representing the relative X position in percent based on the gravity (-1 to 1) ...
Definition: Clip.h:302
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:86
std::string Json() const override
Get and Set JSON methods.
int den
Denominator for the fraction.
Definition: Fraction.h:33
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
Definition: KeyFrame.h:53
Keyframe background_corner
Radius of rounded corners.
This class contains the properties of a tracked object and functions to manipulate it...
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition: ReaderBase.h:48
Constant curves jump from their previous position to a new one (with no interpolation).
Definition: Point.h:31
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Color.cpp:86