You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Changed KeyframeBBox to TrackedObjectBBox and added TrackedObjectBase
Added new base class TrackedObjectBase, changed class KeyframeBBox to TrackedObjectBBox and changes it's inheritance from KeyframeBase to TrackedObjectBase.
This commit is contained in:
@@ -87,7 +87,8 @@ set(OPENSHOT_SOURCES
|
||||
Json.cpp
|
||||
KeyFrame.cpp
|
||||
KeyFrameBase.cpp
|
||||
KeyFrameBBox.cpp
|
||||
TrackedObjectBase.cpp
|
||||
TrackedObjectBBox.cpp
|
||||
OpenShotVersion.cpp
|
||||
ZmqLogger.cpp
|
||||
PlayerBase.cpp
|
||||
|
||||
17
src/Clip.cpp
17
src/Clip.cpp
@@ -251,7 +251,7 @@ void Clip::AttachToTracker(std::string tracked_id)
|
||||
Timeline *parentTimeline = (Timeline *) ParentTimeline();
|
||||
|
||||
// Create a smart pointer to the tracked object from the timeline
|
||||
std::shared_ptr<openshot::KeyframeBase> trackedObject = parentTimeline->GetTrackedObject(tracked_id);
|
||||
std::shared_ptr<openshot::TrackedObjectBase> trackedObject = parentTimeline->GetTrackedObject(tracked_id);
|
||||
|
||||
// Check for valid tracked object
|
||||
if (trackedObject){
|
||||
@@ -264,7 +264,7 @@ void Clip::AttachToTracker(std::string tracked_id)
|
||||
}
|
||||
|
||||
// Set the pointer to the trackedObject this clip is attached to
|
||||
void Clip::SetAttachedObject(std::shared_ptr<openshot::KeyframeBase> trackedObject){
|
||||
void Clip::SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject){
|
||||
attachedObject = trackedObject;
|
||||
return;
|
||||
}
|
||||
@@ -1142,7 +1142,7 @@ void Clip::AddEffect(EffectBase* effect)
|
||||
Tracker* tracker = (Tracker *) effect;
|
||||
|
||||
// Get tracked data from the Tracker effect
|
||||
std::shared_ptr<openshot::KeyFrameBBox> trackedData = tracker->trackedData;
|
||||
std::shared_ptr<openshot::TrackedObjectBBox> trackedData = tracker->trackedData;
|
||||
|
||||
// Add tracked data to the timeline
|
||||
parentTimeline->AddTrackedObject(trackedData);
|
||||
@@ -1279,13 +1279,18 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
|
||||
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
|
||||
double timeline_frame_number = frame->number + clip_start_position - clip_start_frame;
|
||||
|
||||
// Access the KeyframeBBox properties
|
||||
std::map<std::string, float> boxValues = attachedObject->GetBoxValues(timeline_frame_number);
|
||||
// Get attachedObject's parent clip frame number
|
||||
Timeline* parentTimeline = (Timeline *) ParentTimeline();
|
||||
double attachedObjectParentClip_frame_number = timeline_frame_number - clip_start_position + clip_start_frame;
|
||||
|
||||
// Access the TrackedObjectBBox properties
|
||||
std::map<std::string, float> boxValues = attachedObject->GetBoxValues(attachedObjectParentClip_frame_number);
|
||||
|
||||
// Get the bounding-box values and correct them by the clip's reference system
|
||||
box_cx = boxValues["cx"] - 0.5;
|
||||
box_cy = boxValues["cy"] - 0.5;
|
||||
box_sx = boxValues["w"]*boxValues["sx"]*2.0;
|
||||
// box_sx = boxValues["w"]*boxValues["sx"]*2.0;
|
||||
box_sx = boxValues["w"]*boxValues["sx"];
|
||||
box_sy = boxValues["h"]*boxValues["sy"];
|
||||
box_r = boxValues["r"];
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
#include "Fraction.h"
|
||||
#include "Frame.h"
|
||||
#include "KeyFrame.h"
|
||||
#include "KeyFrameBase.h"
|
||||
#include "TrackedObjectBase.h"
|
||||
#include "ReaderBase.h"
|
||||
#include "JuceHeader.h"
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace openshot {
|
||||
std::list<openshot::EffectBase*> effects; ///<List of clips on this timeline
|
||||
bool is_open; ///> Is Reader opened
|
||||
std::string attached_id; ///< Id of the bounding box that this clip is attached to
|
||||
std::shared_ptr<openshot::KeyframeBase> attachedObject;
|
||||
std::shared_ptr<openshot::TrackedObjectBase> attachedObject;
|
||||
|
||||
// Audio resampler (if time mapping)
|
||||
openshot::AudioResampler *resampler;
|
||||
@@ -206,9 +206,9 @@ namespace openshot {
|
||||
void AttachToTracker(std::string tracked_id);
|
||||
|
||||
/// Set the pointer to the trackedObject this clip is attached to
|
||||
void SetAttachedObject(std::shared_ptr<openshot::KeyframeBase> trackedObject);
|
||||
void SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject);
|
||||
/// Return a pointer to the trackedObject this clip is attached to
|
||||
std::shared_ptr<openshot::KeyframeBase> GetAttachedObject() const { return attachedObject; };
|
||||
std::shared_ptr<openshot::TrackedObjectBase> GetAttachedObject() const { return attachedObject; };
|
||||
|
||||
/// Return the type name of the class
|
||||
std::string Name() override { return "Clip"; };
|
||||
|
||||
@@ -98,10 +98,6 @@ namespace openshot{
|
||||
}
|
||||
|
||||
KeyframeBase::KeyframeBase(){
|
||||
id = "TESTBASEID";
|
||||
|
||||
}
|
||||
|
||||
KeyframeBase::KeyframeBase(std::string _id){
|
||||
SetId(_id);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "Point.h"
|
||||
#include "Json.h"
|
||||
|
||||
|
||||
namespace openshot {
|
||||
/**
|
||||
* @brief This abstract class is the base class of all Keyframes.
|
||||
@@ -71,27 +72,16 @@ namespace openshot {
|
||||
// int64_t SearchBetweenPoints(Point const & left, Point const & right, int64_t const current, Check check);
|
||||
|
||||
class KeyframeBase{
|
||||
private:
|
||||
std::string id;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/// Blank constructor
|
||||
KeyframeBase();
|
||||
|
||||
/// Default constructor
|
||||
KeyframeBase(std::string _id);
|
||||
|
||||
std::string Id() const { return id; }
|
||||
void SetId(std::string _id) { id = _id; }
|
||||
|
||||
/// Scale all points by a percentage (good for evenly lengthening or shortening an openshot::Keyframe)
|
||||
/// 1.0 = same size, 1.05 = 5% increase, etc...
|
||||
virtual void ScalePoints(double scale) { return; };
|
||||
|
||||
/// Return the main properties of a KeyframeBBox instance using a pointer to this base class
|
||||
virtual std::map<std::string, float> GetBoxValues(int64_t frame_number) { std::map<std::string, float> ret; return ret; };
|
||||
|
||||
};
|
||||
} // Namespace openshot
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
#include "TextReader.h"
|
||||
#endif
|
||||
#include "KeyFrame.h"
|
||||
#include "KeyFrameBBox.h"
|
||||
#include "TrackedObjectBBox.h"
|
||||
#include "PlayerBase.h"
|
||||
#include "Point.h"
|
||||
#include "Profiles.h"
|
||||
|
||||
@@ -240,8 +240,8 @@ Timeline::~Timeline() {
|
||||
}
|
||||
}
|
||||
|
||||
// Add to the tracked_objects map a pointer to a tracked object (KeyframeBBox)
|
||||
void Timeline::AddTrackedObject(std::shared_ptr<openshot::KeyframeBase> trackedObject){
|
||||
// Add to the tracked_objects map a pointer to a tracked object (TrackedObjectBBox)
|
||||
void Timeline::AddTrackedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject){
|
||||
|
||||
// Search for the tracked object on the map
|
||||
auto iterator = tracked_objects.find(trackedObject->Id());
|
||||
@@ -254,18 +254,19 @@ void Timeline::AddTrackedObject(std::shared_ptr<openshot::KeyframeBase> trackedO
|
||||
// Tracked object's id not present -> insert it on the map
|
||||
tracked_objects[trackedObject->Id()] = trackedObject;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Return tracked object pointer by it's id
|
||||
std::shared_ptr<openshot::KeyframeBase> Timeline::GetTrackedObject(std::string id) const{
|
||||
std::shared_ptr<openshot::TrackedObjectBase> Timeline::GetTrackedObject(std::string id) const{
|
||||
|
||||
// Search for the tracked object on the map
|
||||
auto iterator = tracked_objects.find(id);
|
||||
|
||||
if (iterator != tracked_objects.end()){
|
||||
// Id found, return the pointer to the tracked object
|
||||
std::shared_ptr<openshot::KeyframeBase> trackedObject = iterator->second;
|
||||
std::shared_ptr<openshot::TrackedObjectBase> trackedObject = iterator->second;
|
||||
return trackedObject;
|
||||
}
|
||||
else {
|
||||
@@ -274,15 +275,15 @@ std::shared_ptr<openshot::KeyframeBase> Timeline::GetTrackedObject(std::string i
|
||||
}
|
||||
}
|
||||
|
||||
// Return the ID's of the tracked objects as a vector of strings
|
||||
std::vector<std::string> Timeline::GetTrackedObjectsIds() const{
|
||||
// Return the ID's of the tracked objects as a list of strings
|
||||
std::list<std::string> Timeline::GetTrackedObjectsIds() const{
|
||||
|
||||
// Create a vector of strings
|
||||
std::vector<std::string> trackedObjects_ids;
|
||||
// Create a list of strings
|
||||
std::list<std::string> trackedObjects_ids;
|
||||
|
||||
// Iterate through the tracked_objects map
|
||||
for (auto const& it: tracked_objects){
|
||||
// Add the IDs to the vector
|
||||
// Add the IDs to the list
|
||||
trackedObjects_ids.push_back(it.first);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
#include "Frame.h"
|
||||
#include "FrameMapper.h"
|
||||
#include "KeyFrame.h"
|
||||
#include "KeyFrameBBox.h"
|
||||
#include "KeyFrameBase.h"
|
||||
#include "TrackedObjectBBox.h"
|
||||
#include "TrackedObjectBase.h"
|
||||
#include "OpenMPUtilities.h"
|
||||
#include "ReaderBase.h"
|
||||
#include "Settings.h"
|
||||
@@ -179,7 +179,7 @@ namespace openshot {
|
||||
bool managed_cache; ///< Does this timeline instance manage the cache object
|
||||
std::string path; ///< Optional path of loaded UTF-8 OpenShot JSON project file
|
||||
std::mutex get_frame_mutex; ///< Mutex to protect GetFrame method from different threads calling it
|
||||
std::map<std::string, std::shared_ptr<openshot::KeyframeBase>> tracked_objects; ///< map of KeyframeBBoxes and their IDs
|
||||
std::map<std::string, std::shared_ptr<openshot::TrackedObjectBase>> tracked_objects; ///< map of TrackedObjectBBoxes and their IDs
|
||||
|
||||
/// Process a new layer of video or audio
|
||||
void add_layer(std::shared_ptr<openshot::Frame> new_frame, openshot::Clip* source_clip, int64_t clip_frame_number, int64_t timeline_frame_number, bool is_top_clip, float max_volume);
|
||||
@@ -244,12 +244,12 @@ namespace openshot {
|
||||
|
||||
virtual ~Timeline();
|
||||
|
||||
/// Add to the tracked_objects map a pointer to a tracked object (KeyframeBBox)
|
||||
void AddTrackedObject(std::shared_ptr<openshot::KeyframeBase> trackedObject);
|
||||
/// Add to the tracked_objects map a pointer to a tracked object (TrackedObjectBBox)
|
||||
void AddTrackedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject);
|
||||
/// Return tracked object pointer by it's id
|
||||
std::shared_ptr<openshot::KeyframeBase> GetTrackedObject(std::string id) const;
|
||||
/// Return the ID's of the tracked objects as a vector of strings
|
||||
std::vector<std::string> GetTrackedObjectsIds() const;
|
||||
std::shared_ptr<openshot::TrackedObjectBase> GetTrackedObject(std::string id) const;
|
||||
/// Return the ID's of the tracked objects as a list of strings
|
||||
std::list<std::string> GetTrackedObjectsIds() const;
|
||||
|
||||
/// @brief Add an openshot::Clip to the timeline
|
||||
/// @param clip Add an openshot::Clip to the timeline. A clip can contain any type of Reader.
|
||||
|
||||
@@ -45,6 +45,5 @@ TimelineBase::TimelineBase()
|
||||
* the TimelineBase class
|
||||
*/
|
||||
void TimelineBase::Clips(int test){
|
||||
std::cout << test << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -28,7 +28,8 @@
|
||||
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "KeyFrameBBox.h"
|
||||
#include "TrackedObjectBBox.h"
|
||||
#include "Clip.h"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -39,14 +40,14 @@ using namespace openshot;
|
||||
|
||||
|
||||
// Default Constructor that sets the bounding-box displacement as 0 and the scales as 1 for the first frame
|
||||
KeyFrameBBox::KeyFrameBBox() : delta_x(0.0), delta_y(0.0), scale_x(1.0), scale_y(1.0), rotation(0.0)
|
||||
TrackedObjectBBox::TrackedObjectBBox() : delta_x(0.0), delta_y(0.0), scale_x(1.0), scale_y(1.0), rotation(0.0)
|
||||
{
|
||||
this->TimeScale = 1.0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a BBox to the BoxVec map
|
||||
void KeyFrameBBox::AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle)
|
||||
void TrackedObjectBBox::AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle)
|
||||
{
|
||||
// Check if the given frame number is valid
|
||||
if (_frame_num < 0)
|
||||
@@ -73,7 +74,7 @@ void KeyFrameBBox::AddBox(int64_t _frame_num, float _cx, float _cy, float _width
|
||||
}
|
||||
|
||||
// Get the size of BoxVec map
|
||||
int64_t KeyFrameBBox::GetLength() const
|
||||
int64_t TrackedObjectBBox::GetLength() const
|
||||
{
|
||||
if (BoxVec.empty())
|
||||
return 0;
|
||||
@@ -83,7 +84,7 @@ int64_t KeyFrameBBox::GetLength() const
|
||||
}
|
||||
|
||||
// Check if there is a bounding-box in the given frame
|
||||
bool KeyFrameBBox::Contains(int64_t frame_num)
|
||||
bool TrackedObjectBBox::Contains(int64_t frame_num)
|
||||
{
|
||||
// Get the time of given frame
|
||||
double time = this->FrameNToTime(frame_num, 1.0);
|
||||
@@ -96,7 +97,7 @@ bool KeyFrameBBox::Contains(int64_t frame_num)
|
||||
}
|
||||
|
||||
// Remove a bounding-box from the BoxVec map
|
||||
void KeyFrameBBox::RemoveBox(int64_t frame_number)
|
||||
void TrackedObjectBBox::RemoveBox(int64_t frame_number)
|
||||
{
|
||||
// Get the time of given frame
|
||||
double time = this->FrameNToTime(frame_number, 1.0);
|
||||
@@ -111,7 +112,7 @@ void KeyFrameBBox::RemoveBox(int64_t frame_number)
|
||||
}
|
||||
|
||||
// Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes
|
||||
BBox KeyFrameBBox::GetBox(int64_t frame_number)
|
||||
BBox TrackedObjectBBox::GetBox(int64_t frame_number)
|
||||
{
|
||||
// Get the time position of the given frame.
|
||||
double time = this->FrameNToTime(frame_number, this->TimeScale);
|
||||
@@ -164,7 +165,7 @@ BBox KeyFrameBBox::GetBox(int64_t frame_number)
|
||||
}
|
||||
|
||||
// Interpolate the bouding-boxes properties
|
||||
BBox KeyFrameBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
|
||||
BBox TrackedObjectBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target)
|
||||
{
|
||||
// Interpolate the x-coordinate of the center point
|
||||
Point cx_left(t1, left.cx, openshot::InterpolationType::LINEAR);
|
||||
@@ -198,30 +199,30 @@ BBox KeyFrameBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right,
|
||||
}
|
||||
|
||||
// Update object's BaseFps
|
||||
void KeyFrameBBox::SetBaseFPS(Fraction fps){
|
||||
void TrackedObjectBBox::SetBaseFPS(Fraction fps){
|
||||
this->BaseFps = fps;
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the object's BaseFps
|
||||
Fraction KeyFrameBBox::GetBaseFPS(){
|
||||
Fraction TrackedObjectBBox::GetBaseFPS(){
|
||||
return BaseFps;
|
||||
}
|
||||
|
||||
// Get the time of the given frame
|
||||
double KeyFrameBBox::FrameNToTime(int64_t frame_number, double time_scale){
|
||||
double TrackedObjectBBox::FrameNToTime(int64_t frame_number, double time_scale){
|
||||
double time = ((double)frame_number) * this->BaseFps.Reciprocal().ToDouble() * (1.0 / time_scale);
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
// Update the TimeScale member variable
|
||||
void KeyFrameBBox::ScalePoints(double time_scale){
|
||||
void TrackedObjectBBox::ScalePoints(double time_scale){
|
||||
this->TimeScale = time_scale;
|
||||
}
|
||||
|
||||
// Load the bounding-boxes information from the protobuf file
|
||||
bool KeyFrameBBox::LoadBoxData(std::string inputFilePath)
|
||||
bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
|
||||
{
|
||||
// Variable to hold the loaded data
|
||||
pb_tracker::Tracker bboxMessage;
|
||||
@@ -277,20 +278,20 @@ bool KeyFrameBBox::LoadBoxData(std::string inputFilePath)
|
||||
}
|
||||
|
||||
// Clear the BoxVec map
|
||||
void KeyFrameBBox::clear()
|
||||
void TrackedObjectBBox::clear()
|
||||
{
|
||||
BoxVec.clear();
|
||||
}
|
||||
|
||||
// Generate JSON string of this object
|
||||
std::string KeyFrameBBox::Json() const
|
||||
std::string TrackedObjectBBox::Json() const
|
||||
{
|
||||
// Return formatted string
|
||||
return JsonValue().toStyledString();
|
||||
}
|
||||
|
||||
// Generate Json::Value for this object
|
||||
Json::Value KeyFrameBBox::JsonValue() const
|
||||
Json::Value TrackedObjectBBox::JsonValue() const
|
||||
{
|
||||
// Create root json object
|
||||
Json::Value root;
|
||||
@@ -313,7 +314,7 @@ Json::Value KeyFrameBBox::JsonValue() const
|
||||
}
|
||||
|
||||
// Load JSON string into this object
|
||||
void KeyFrameBBox::SetJson(const std::string value)
|
||||
void TrackedObjectBBox::SetJson(const std::string value)
|
||||
{
|
||||
// Parse JSON string into JSON objects
|
||||
try
|
||||
@@ -331,12 +332,12 @@ void KeyFrameBBox::SetJson(const std::string value)
|
||||
}
|
||||
|
||||
// Load Json::Value into this object
|
||||
void KeyFrameBBox::SetJsonValue(const Json::Value root)
|
||||
void TrackedObjectBBox::SetJsonValue(const Json::Value root)
|
||||
{
|
||||
|
||||
// Set the Id
|
||||
if (!root["box_id"].isNull())
|
||||
SetId(root["box_id"].asString());
|
||||
Id(root["box_id"].asString());
|
||||
|
||||
// Set the BaseFps by the given JSON object
|
||||
if (!root["BaseFPS"].isNull() && root["BaseFPS"].isObject())
|
||||
@@ -374,7 +375,7 @@ void KeyFrameBBox::SetJsonValue(const Json::Value root)
|
||||
|
||||
// Get all properties for a specific frame (perfect for a UI to display the current state
|
||||
// of all properties at any time)
|
||||
Json::Value KeyFrameBBox::PropertiesJSON(int64_t requested_frame) const
|
||||
Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const
|
||||
{
|
||||
Json::Value root;
|
||||
|
||||
@@ -402,7 +403,7 @@ Json::Value KeyFrameBBox::PropertiesJSON(int64_t requested_frame) const
|
||||
|
||||
|
||||
// Generate JSON for a property
|
||||
Json::Value KeyFrameBBox::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 {
|
||||
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 {
|
||||
|
||||
// Requested Point
|
||||
const Point requested_point(requested_frame, requested_frame);
|
||||
@@ -439,7 +440,7 @@ Json::Value KeyFrameBBox::add_property_json(std::string name, float value, std::
|
||||
}
|
||||
|
||||
// Return the bounding box properties and it's keyframes indexed by their names
|
||||
std::map<std::string, float> KeyFrameBBox::GetBoxValues(int64_t frame_number){
|
||||
std::map<std::string, float> TrackedObjectBBox::GetBoxValues(int64_t frame_number){
|
||||
|
||||
// Create the map
|
||||
std::map<std::string, float> boxValues;
|
||||
@@ -463,4 +464,35 @@ std::map<std::string, float> KeyFrameBBox::GetBoxValues(int64_t frame_number){
|
||||
|
||||
|
||||
return boxValues;
|
||||
}
|
||||
|
||||
// Return properties of this object's parent clip
|
||||
std::map<std::string, float> TrackedObjectBBox::GetParentClipProperties(int64_t frame_number){
|
||||
|
||||
// Get the parent clip of this object as a Clip pointer
|
||||
Clip* parentClip = (Clip *) ParentClip();
|
||||
|
||||
// Calculate parentClip's frame number
|
||||
long parentClip_start_position = round( parentClip->Position() * parentClip->info.fps.ToDouble() ) + 1;
|
||||
long parentClip_start_frame = ( parentClip->Start() * parentClip->info.fps.ToDouble() ) + 1;
|
||||
float parentClip_frame_number = frame_number - parentClip_start_position + parentClip_start_frame;
|
||||
|
||||
// Get parentClip's Keyframes
|
||||
float parentClip_location_x = parentClip->location_x.GetValue(parentClip_frame_number);
|
||||
float parentClip_location_y = parentClip->location_y.GetValue(parentClip_frame_number);
|
||||
float parentClip_scale_x = parentClip->scale_x.GetValue(parentClip_frame_number);
|
||||
float parentClip_scale_y = parentClip->scale_y.GetValue(parentClip_frame_number);
|
||||
float parentClip_rotation = parentClip->rotation.GetValue(parentClip_frame_number);
|
||||
|
||||
std::map<std::string, float> parentClipProperties;
|
||||
|
||||
parentClipProperties["frame_number"] = parentClip_frame_number;
|
||||
parentClipProperties["timeline_frame_number"] = frame_number;
|
||||
parentClipProperties["location_x"] = parentClip_location_x;
|
||||
parentClipProperties["location_y"] = parentClip_location_y;
|
||||
parentClipProperties["scale_x"] = parentClip_scale_x;
|
||||
parentClipProperties["scale_y"] = parentClip_scale_y;
|
||||
parentClipProperties["rotation"] = parentClip_rotation;
|
||||
|
||||
return parentClipProperties;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Header file for the KeyFrameBBox class
|
||||
* @brief Header file for the TrackedObjectBBox class
|
||||
* @author Jonathan Thomas <jonathan@openshot.org>
|
||||
*
|
||||
* @ref License
|
||||
@@ -28,8 +28,8 @@
|
||||
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPENSHOT_BBOXKEYFRAME_H
|
||||
#define OPENSHOT_BBOXKEYFRAME_H
|
||||
#ifndef OPENSHOT_TRACKEDOBJECTBBOX_H
|
||||
#define OPENSHOT_TRACKEDOBJECTBBOX_H
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "Point.h"
|
||||
#include "Json.h"
|
||||
#include "KeyFrame.h"
|
||||
#include "KeyFrameBase.h"
|
||||
#include "TrackedObjectBase.h"
|
||||
#include "protobuf_messages/trackerdata.pb.h"
|
||||
#include <google/protobuf/util/time_util.h>
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace openshot
|
||||
* object of this class.
|
||||
*/
|
||||
|
||||
class KeyFrameBBox : public KeyframeBase
|
||||
class TrackedObjectBBox : public TrackedObjectBase
|
||||
{
|
||||
private:
|
||||
bool visible;
|
||||
@@ -171,7 +171,7 @@ namespace openshot
|
||||
std::string protobufDataPath; ///< Path to the protobuf file that holds the bbox points across the frames
|
||||
|
||||
/// Default Constructor
|
||||
KeyFrameBBox();
|
||||
TrackedObjectBBox();
|
||||
|
||||
/// Add a BBox to the BoxVec map
|
||||
void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle);
|
||||
@@ -197,7 +197,7 @@ namespace openshot
|
||||
/// Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes
|
||||
BBox GetBox(int64_t frame_number) const
|
||||
{
|
||||
return const_cast<KeyFrameBBox *>(this)->GetBox(frame_number);
|
||||
return const_cast<TrackedObjectBBox *>(this)->GetBox(frame_number);
|
||||
}
|
||||
BBox GetBox(int64_t frame_number);
|
||||
|
||||
@@ -227,7 +227,9 @@ namespace openshot
|
||||
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;
|
||||
|
||||
/// Return the bounding box properties and it's keyframes indexed by their names
|
||||
std::map<std::string, float> GetBoxValues(int64_t frame_number) override;
|
||||
std::map<std::string, float> GetBoxValues(int64_t frame_number) override;
|
||||
/// Return properties of this object's parent clip
|
||||
std::map<std::string, float> GetParentClipProperties(int64_t frame_number);
|
||||
|
||||
};
|
||||
} // namespace openshot
|
||||
46
src/TrackedObjectBase.cpp
Normal file
46
src/TrackedObjectBase.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Source file for the TrackedObjectBase class
|
||||
* @author Jonathan Thomas <jonathan@openshot.org>
|
||||
*
|
||||
* @ref License
|
||||
*/
|
||||
|
||||
/* LICENSE
|
||||
*
|
||||
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
||||
* <http://www.openshotstudios.com/>. This file is part of
|
||||
* OpenShot Library (libopenshot), an open-source project dedicated to
|
||||
* delivering high quality video editing and animation solutions to the
|
||||
* world. For more information visit <http://www.openshot.org/>.
|
||||
*
|
||||
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TrackedObjectBase.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace openshot{
|
||||
|
||||
TrackedObjectBase::TrackedObjectBase(){
|
||||
id = "None";
|
||||
}
|
||||
|
||||
TrackedObjectBase::TrackedObjectBase(std::string _id){
|
||||
Id(_id);
|
||||
}
|
||||
}
|
||||
97
src/TrackedObjectBase.h
Normal file
97
src/TrackedObjectBase.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Header file for the TrackedObjectBase class
|
||||
* @author Jonathan Thomas <jonathan@openshot.org>
|
||||
*
|
||||
* @ref License
|
||||
*/
|
||||
|
||||
/* LICENSE
|
||||
*
|
||||
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
||||
* <http://www.openshotstudios.com/>. This file is part of
|
||||
* OpenShot Library (libopenshot), an open-source project dedicated to
|
||||
* delivering high quality video editing and animation solutions to the
|
||||
* world. For more information visit <http://www.openshot.org/>.
|
||||
*
|
||||
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPENSHOT_TRACKEDOBJECTBASE_H
|
||||
#define OPENSHOT_TRACKEDOBJECTBASE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Exceptions.h"
|
||||
#include "Fraction.h"
|
||||
#include "Coordinate.h"
|
||||
#include "Point.h"
|
||||
#include "Json.h"
|
||||
#include "ClipBase.h"
|
||||
|
||||
|
||||
namespace openshot {
|
||||
/**
|
||||
* @brief This abstract class is the base class of all Keyframes.
|
||||
*
|
||||
* A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
|
||||
*
|
||||
* Keyframes are used to animate and interpolate values of properties over time. For example, a single property
|
||||
* can use a Keyframe instead of a constant value. Assume you want to slide an image (from left to right) over
|
||||
* a video. You can create a Keyframe which will adjust the X value of the image over 100 frames (or however many
|
||||
* frames the animation needs to last) from the value of 0 to 640.
|
||||
*/
|
||||
|
||||
class TrackedObjectBase {
|
||||
private:
|
||||
std::string id;
|
||||
ClipBase* parentClip;
|
||||
|
||||
public:
|
||||
|
||||
/// Blank constructor
|
||||
TrackedObjectBase();
|
||||
|
||||
/// Default constructor
|
||||
TrackedObjectBase(std::string _id);
|
||||
|
||||
/// Get and set the id of this object
|
||||
std::string Id() const { return id; }
|
||||
void Id(std::string _id) { id = _id; }
|
||||
/// Get and set the parentClip of this object
|
||||
ClipBase* ParentClip() { return parentClip; }
|
||||
void ParentClip(ClipBase* clip) { parentClip = clip; }
|
||||
|
||||
/// Scale a property
|
||||
virtual void ScalePoints(double scale) { return; };
|
||||
/// Return the main properties of a TrackedObjectBBox instance using a pointer to this base class
|
||||
virtual std::map<std::string, float> GetBoxValues(int64_t frame_number) { std::map<std::string, float> ret; return ret; };
|
||||
/// Return the main properties of the tracked object's parent clip
|
||||
virtual std::map<std::string, float> GetParentClipProperties(int64_t frame_number) { std::map<std::string, float> ret; return ret; }
|
||||
|
||||
/// Get and Set JSON methods
|
||||
virtual std::string Json() const = 0; ///< Generate JSON string of this object
|
||||
virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object
|
||||
virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object
|
||||
virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object
|
||||
|
||||
|
||||
};
|
||||
} // Namespace openshot
|
||||
|
||||
#endif
|
||||
@@ -41,11 +41,13 @@ Tracker::Tracker(std::string clipTrackerDataPath)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
// Instantiate a keyframebbox object and point to it
|
||||
KeyFrameBBox trackedDataObject;
|
||||
trackedData = std::make_shared<KeyFrameBBox>(trackedDataObject);
|
||||
// Instantiate a TrackedObjectBBox object and point to it
|
||||
TrackedObjectBBox trackedDataObject;
|
||||
trackedData = std::make_shared<TrackedObjectBBox>(trackedDataObject);
|
||||
// Tries to load the tracked object's data from protobuf file
|
||||
trackedData->LoadBoxData(clipTrackerDataPath);
|
||||
ClipBase* parentClip = this->ParentClip();
|
||||
trackedData->ParentClip(parentClip);
|
||||
}
|
||||
|
||||
// Default constructor
|
||||
@@ -53,9 +55,11 @@ Tracker::Tracker()
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
// Instantiate a keyframebbox object and point to it
|
||||
KeyFrameBBox trackedDataObject;
|
||||
trackedData = std::make_shared<KeyFrameBBox>(trackedDataObject);
|
||||
// Instantiate a TrackedObjectBBox object and point to it
|
||||
TrackedObjectBBox trackedDataObject;
|
||||
trackedData = std::make_shared<TrackedObjectBBox>(trackedDataObject);
|
||||
ClipBase* parentClip = this->ParentClip();
|
||||
trackedData->ParentClip(parentClip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include "../Json.h"
|
||||
#include "../KeyFrame.h"
|
||||
#include "protobuf_messages/trackerdata.pb.h"
|
||||
#include "../KeyFrameBBox.h"
|
||||
#include "../TrackedObjectBBox.h"
|
||||
#include "../Clip.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -63,7 +63,7 @@ namespace openshot
|
||||
|
||||
public:
|
||||
std::string protobuf_data_path; ///< Path to the protobuf file that holds the bounding-box data
|
||||
std::shared_ptr<KeyFrameBBox> trackedData; ///< Pointer to an object that holds the bounding-box data and it's Keyframes
|
||||
std::shared_ptr<TrackedObjectBBox> trackedData; ///< Pointer to an object that holds the bounding-box data and it's Keyframes
|
||||
|
||||
/// Blank constructor, useful when using Json to load the effect properties
|
||||
Tracker(std::string clipTrackerDataPath);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
// Prevent name clashes with juce::UnitTest
|
||||
#define DONT_SET_USING_JUCE_NAMESPACE 1
|
||||
#include "KeyFrame.h"
|
||||
#include "KeyFrameBBox.h"
|
||||
#include "TrackedObjectBBox.h"
|
||||
#include "Coordinate.h"
|
||||
#include "Fraction.h"
|
||||
#include "Clip.h"
|
||||
@@ -506,14 +506,14 @@ TEST(Keyframe_Handle_Large_Segment)
|
||||
}
|
||||
|
||||
|
||||
TEST(KeyFrameBBox_init_test) {
|
||||
TEST(TrackedObjectBBox_init_test) {
|
||||
|
||||
KeyFrameBBox kfb;
|
||||
TrackedObjectBBox kfb;
|
||||
|
||||
}
|
||||
|
||||
TEST(KeyFrameBBox_addBox_test) {
|
||||
KeyFrameBBox kfb;
|
||||
TEST(TrackedObjectBBox_addBox_test) {
|
||||
TrackedObjectBBox kfb;
|
||||
|
||||
kfb.AddBox(1, 10.0, 10.0, 100.0, 100.0, 0.0);
|
||||
|
||||
@@ -527,8 +527,8 @@ TEST(KeyFrameBBox_addBox_test) {
|
||||
}
|
||||
|
||||
|
||||
TEST(KeyFrameBBox_GetVal_test) {
|
||||
KeyFrameBBox kfb;
|
||||
TEST(TrackedObjectBBox_GetVal_test) {
|
||||
TrackedObjectBBox kfb;
|
||||
|
||||
kfb.AddBox(1, 10.0, 10.0, 100.0, 100.0, 0.0);
|
||||
|
||||
@@ -542,8 +542,8 @@ TEST(KeyFrameBBox_GetVal_test) {
|
||||
}
|
||||
|
||||
|
||||
TEST(KeyFrameBBox_GetVal_Interpolation) {
|
||||
KeyFrameBBox kfb;
|
||||
TEST(TrackedObjectBBox_GetVal_Interpolation) {
|
||||
TrackedObjectBBox kfb;
|
||||
|
||||
kfb.AddBox(1, 10.0, 10.0, 100.0, 100.0, 0.0);
|
||||
kfb.AddBox(11, 20.0, 20.0, 100.0, 100.0, 0.0);
|
||||
@@ -574,8 +574,8 @@ TEST(KeyFrameBBox_GetVal_Interpolation) {
|
||||
}
|
||||
|
||||
|
||||
TEST(KeyFrameBBox_Json_set) {
|
||||
KeyFrameBBox kfb;
|
||||
TEST(TrackedObjectBBox_Json_set) {
|
||||
TrackedObjectBBox kfb;
|
||||
|
||||
kfb.AddBox(1, 10.0, 10.0, 100.0, 100.0, 0.0);
|
||||
kfb.AddBox(10, 20.0, 20.0, 100.0, 100.0, 0.0);
|
||||
@@ -588,7 +588,7 @@ TEST(KeyFrameBBox_Json_set) {
|
||||
kfb.SetBaseFPS(Fraction(24.0, 1.0));
|
||||
|
||||
auto dataJSON = kfb.Json();
|
||||
KeyFrameBBox fromJSON_kfb;
|
||||
TrackedObjectBBox fromJSON_kfb;
|
||||
fromJSON_kfb.SetJson(dataJSON);
|
||||
|
||||
CHECK_EQUAL(kfb.GetBaseFPS().num, fromJSON_kfb.GetBaseFPS().num);
|
||||
@@ -607,8 +607,8 @@ TEST(KeyFrameBBox_Json_set) {
|
||||
CHECK_EQUAL(kfb_bbox.angle, fromJSON_bbox.angle);
|
||||
}
|
||||
|
||||
TEST(KeyFrameBBox_Scale_test){
|
||||
KeyFrameBBox kfb;
|
||||
TEST(TrackedObjectBBox_Scale_test){
|
||||
TrackedObjectBBox kfb;
|
||||
|
||||
kfb.AddBox(1, 10.0, 10.0, 10.0, 10.0, 0.0);
|
||||
kfb.scale_x.AddPoint(1.0, 2.0);
|
||||
@@ -646,7 +646,7 @@ TEST(Attach_test){
|
||||
clip.AddEffect(&tracker);
|
||||
|
||||
// Save a pointer to trackedData
|
||||
std::shared_ptr<KeyFrameBBox> trackedData = tracker.trackedData;
|
||||
std::shared_ptr<TrackedObjectBBox> trackedData = tracker.trackedData;
|
||||
|
||||
// Change trackedData scale
|
||||
trackedData->scale_x.AddPoint(1, 2.0);
|
||||
@@ -656,8 +656,8 @@ TEST(Attach_test){
|
||||
auto trackedDataJson = trackedData->JsonValue();
|
||||
|
||||
// Get and cast the trakcedObject
|
||||
auto trackedObject_base = t.GetTrackedObject("TESTBASEID");
|
||||
std::shared_ptr<KeyFrameBBox> trackedObject = std::static_pointer_cast<KeyFrameBBox>(trackedObject_base);
|
||||
auto trackedObject_base = t.GetTrackedObject("None");
|
||||
std::shared_ptr<TrackedObjectBBox> trackedObject = std::static_pointer_cast<TrackedObjectBBox>(trackedObject_base);
|
||||
CHECK_EQUAL(trackedData, trackedObject);
|
||||
|
||||
// Set trackedObject Json Value
|
||||
@@ -668,7 +668,7 @@ TEST(Attach_test){
|
||||
childClip.Open();
|
||||
childClip.AttachToTracker(tracked_id);
|
||||
|
||||
std::shared_ptr<KeyFrameBBox> trackedTest = std::static_pointer_cast<KeyFrameBBox>(childClip.GetAttachedObject());
|
||||
std::shared_ptr<TrackedObjectBBox> trackedTest = std::static_pointer_cast<TrackedObjectBBox>(childClip.GetAttachedObject());
|
||||
|
||||
CHECK_EQUAL(trackedData->scale_x.GetValue(1), trackedTest->scale_x.GetValue(1));
|
||||
|
||||
@@ -678,10 +678,10 @@ TEST(Attach_test){
|
||||
|
||||
TEST(GetBoxValues_test){
|
||||
|
||||
KeyFrameBBox trackedDataObject;
|
||||
TrackedObjectBBox trackedDataObject;
|
||||
trackedDataObject.AddBox(1, 10.0, 10.0, 20.0, 20.0, 30.0);
|
||||
|
||||
std::shared_ptr<KeyframeBase> trackedData = std::make_shared<KeyFrameBBox>(trackedDataObject);
|
||||
std::shared_ptr<TrackedObjectBase> trackedData = std::make_shared<TrackedObjectBBox>(trackedDataObject);
|
||||
|
||||
auto boxValues = trackedData->GetBoxValues(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user