Loading...
Searching...
No Matches
TrackedObjectBBox.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_TRACKEDOBJECTBBOX_H
#define OPENSHOT_TRACKEDOBJECTBBOX_H
#include "TrackedObjectBase.h"
#include "Color.h"
#include "Exceptions.h"
#include "Fraction.h"
#include "Json.h"
#include "KeyFrame.h"
namespace openshot
{
struct BBox
{
float cx = -1;
float cy = -1;
float width = -1;
float height = -1;
float angle = -1;
BBox() {}
BBox(float _cx, float _cy, float _width, float _height, float _angle)
{
cx = _cx;
cy = _cy;
width = _width;
height = _height;
angle = _angle;
}
std::string Json() const
{
return JsonValue().toStyledString();
}
Json::Value JsonValue() const
{
Json::Value root;
root["cx"] = cx;
root["cy"] = cy;
root["width"] = width;
root["height"] = height;
root["angle"] = angle;
return root;
}
void SetJson(const std::string value)
{
// Parse JSON string into JSON objects
try
{
const Json::Value root = openshot::stringToJson(value);
// Set all values that match
SetJsonValue(root);
}
catch (const std::exception &e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
}
void SetJsonValue(const Json::Value root)
{
// Set data from Json (if key is found)
if (!root["cx"].isNull())
cx = root["cx"].asDouble();
if (!root["cy"].isNull())
cy = root["cy"].asDouble();
if (!root["width"].isNull())
width = root["width"].asDouble();
if (!root["height"].isNull())
height = root["height"].asDouble();
if (!root["angle"].isNull())
angle = root["angle"].asDouble();
}
};
class TrackedObjectBBox : public TrackedObjectBase
{
private:
Fraction BaseFps;
double TimeScale;
public:
std::map<double, BBox> BoxVec;
Keyframe delta_x;
Keyframe delta_y;
Keyframe scale_x;
Keyframe scale_y;
Keyframe rotation;
Keyframe background_alpha;
Keyframe background_corner;
Keyframe stroke_width;
Keyframe stroke_alpha;
Color stroke;
Color background;
std::string protobufDataPath;
TrackedObjectBBox();
TrackedObjectBBox(int Red, int Green, int Blue, int Alfa);
void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle) override;
void SetBaseFPS(Fraction fps);
Fraction GetBaseFPS();
void ScalePoints(double scale) override;
bool Contains(int64_t frame_number) const;
bool ExactlyContains(int64_t frame_number) const override;
int64_t GetLength() const;
void RemoveBox(int64_t frame_number);
BBox GetBox(int64_t frame_number);
BBox GetBox(int64_t frame_number) const
{
return const_cast<TrackedObjectBBox *>(this)->GetBox(frame_number);
}
bool LoadBoxData(std::string inputFilePath);
double FrameNToTime(int64_t frame_number, double time_scale) const;
BBox InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target);
void clear();
std::string Json() const override;
Json::Value JsonValue() const override;
void SetJson(const std::string value) override;
void SetJsonValue(const Json::Value root) override;
Json::Value PropertiesJSON(int64_t requested_frame) const override;
// Generate JSON for a property
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;
std::map<std::string, float> GetBoxValues(int64_t frame_number) const override;
std::map<std::string, float> GetParentClipProperties(int64_t frame_number) const override;
};
} // namespace openshot
#endif
Color.h
Header file for Color class.
Exceptions.h
Header file for all Exception classes.
Fraction.h
Header file for Fraction class.
Json.h
Header file for JSON class.
KeyFrame.h
Header file for the Keyframe class.
TrackedObjectBase.h
Header file for the TrackedObjectBase class.
openshot::Color
This class represents a color (used on the timeline and clips)
Definition Color.h:27
openshot::Fraction
This class represents a fraction.
Definition Fraction.h:30
openshot::InvalidJSON
Exception for invalid JSON.
Definition Exceptions.h:218
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::TrackedObjectBBox
This class contains the properties of a tracked object and functions to manipulate it.
Definition TrackedObjectBBox.h:131
openshot::TrackedObjectBBox::delta_x
Keyframe delta_x
X-direction displacement Keyframe.
Definition TrackedObjectBBox.h:138
openshot::TrackedObjectBBox::LoadBoxData
bool LoadBoxData(std::string inputFilePath)
Load the bounding-boxes information from the protobuf file.
Definition TrackedObjectBBox.cpp:236
openshot::TrackedObjectBBox::stroke
Color stroke
Border line color.
Definition TrackedObjectBBox.h:147
openshot::TrackedObjectBBox::rotation
Keyframe rotation
Rotation Keyframe.
Definition TrackedObjectBBox.h:142
openshot::TrackedObjectBBox::GetLength
int64_t GetLength() const
Get the size of BoxVec map.
Definition TrackedObjectBBox.cpp:73
openshot::TrackedObjectBBox::stroke_width
Keyframe stroke_width
Thickness of border line.
Definition TrackedObjectBBox.h:145
openshot::TrackedObjectBBox::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition TrackedObjectBBox.cpp:358
openshot::TrackedObjectBBox::GetParentClipProperties
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.
Definition TrackedObjectBBox.cpp:535
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:46
openshot::TrackedObjectBBox::TrackedObjectBBox
TrackedObjectBBox()
Default Constructor.
Definition TrackedObjectBBox.cpp:28
openshot::TrackedObjectBBox::SetBaseFPS
void SetBaseFPS(Fraction fps)
Update object's BaseFps.
Definition TrackedObjectBBox.cpp:213
openshot::TrackedObjectBBox::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition TrackedObjectBBox.cpp:340
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:471
openshot::TrackedObjectBBox::clear
void clear()
Clear the BoxVec map.
Definition TrackedObjectBBox.cpp:295
openshot::TrackedObjectBBox::delta_y
Keyframe delta_y
Y-direction displacement Keyframe.
Definition TrackedObjectBBox.h:139
openshot::TrackedObjectBBox::background
Color background
Background fill color.
Definition TrackedObjectBBox.h:148
openshot::TrackedObjectBBox::GetBox
BBox GetBox(int64_t frame_number) const
Const-cast of the GetBox function, so that it can be called inside other cont function.
Definition TrackedObjectBBox.h:182
openshot::TrackedObjectBBox::BoxVec
std::map< double, BBox > BoxVec
Index the bounding-box by time of each frame.
Definition TrackedObjectBBox.h:137
openshot::TrackedObjectBBox::Json
std::string Json() const override
Get and Set JSON methods.
Definition TrackedObjectBBox.cpp:301
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:97
openshot::TrackedObjectBBox::ScalePoints
void ScalePoints(double scale) override
Update the TimeScale member variable.
Definition TrackedObjectBBox.cpp:231
openshot::TrackedObjectBBox::InterpolateBoxes
BBox InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
Interpolate the bouding-boxes properties.
Definition TrackedObjectBBox.cpp:179
openshot::TrackedObjectBBox::GetBaseFPS
Fraction GetBaseFPS()
Return the object's BaseFps.
Definition TrackedObjectBBox.cpp:219
openshot::TrackedObjectBBox::PropertiesJSON
Json::Value PropertiesJSON(int64_t requested_frame) const override
Definition TrackedObjectBBox.cpp:420
openshot::TrackedObjectBBox::background_alpha
Keyframe background_alpha
Background box opacity.
Definition TrackedObjectBBox.h:143
openshot::TrackedObjectBBox::RemoveBox
void RemoveBox(int64_t frame_number)
Remove a bounding-box from the BoxVec map.
Definition TrackedObjectBBox.cpp:111
openshot::TrackedObjectBBox::Contains
bool Contains(int64_t frame_number) const
Check if there is a bounding-box in the given frame.
Definition TrackedObjectBBox.cpp:83
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:508
openshot::TrackedObjectBBox::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition TrackedObjectBBox.cpp:308
openshot::TrackedObjectBBox::scale_y
Keyframe scale_y
Y-direction scale Keyframe.
Definition TrackedObjectBBox.h:141
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::TrackedObjectBBox::stroke_alpha
Keyframe stroke_alpha
Stroke box opacity.
Definition TrackedObjectBBox.h:146
openshot::TrackedObjectBBox::FrameNToTime
double FrameNToTime(int64_t frame_number, double time_scale) const
Get the time of the given frame.
Definition TrackedObjectBBox.cpp:224
openshot::TrackedObjectBBox::scale_x
Keyframe scale_x
X-direction scale Keyframe.
Definition TrackedObjectBBox.h:140
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:126
openshot::TrackedObjectBBox::background_corner
Keyframe background_corner
Radius of rounded corners.
Definition TrackedObjectBBox.h:144
openshot::TrackedObjectBase
This abstract class is the base class of all Tracked Objects.
Definition TrackedObjectBase.h:35
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition Json.cpp:16
openshot::BBox
This struct holds the information of a bounding-box.
Definition TrackedObjectBBox.h:38
openshot::BBox::cy
float cy
y-coordinate of the bounding box center
Definition TrackedObjectBBox.h:40
openshot::BBox::height
float height
bounding box height
Definition TrackedObjectBBox.h:42
openshot::BBox::cx
float cx
x-coordinate of the bounding box center
Definition TrackedObjectBBox.h:39
openshot::BBox::Json
std::string Json() const
Generate JSON string of this object.
Definition TrackedObjectBBox.h:65
openshot::BBox::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition TrackedObjectBBox.h:84
openshot::BBox::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition TrackedObjectBBox.h:71
openshot::BBox::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition TrackedObjectBBox.h:101
openshot::BBox::BBox
BBox(float _cx, float _cy, float _width, float _height, float _angle)
Definition TrackedObjectBBox.h:54
openshot::BBox::BBox
BBox()
Blank constructor.
Definition TrackedObjectBBox.h:46
openshot::BBox::width
float width
bounding box width
Definition TrackedObjectBBox.h:41
openshot::BBox::angle
float angle
bounding box rotation angle [degrees]
Definition TrackedObjectBBox.h:43