Skip to content

Commit

Permalink
Added support to set the visibility of a Tracked Object
Browse files Browse the repository at this point in the history
Added the property "Keyframe visible"  to TrackedObjectBase, so the user can set the Tracked Object to be visible or invisible  along the chosen frames.
  • Loading branch information
BrennoCaldato committed Feb 4, 2021
1 parent 9df3b51 commit 2e47325
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/TrackedObjectBBox.cpp
Expand Up @@ -323,6 +323,7 @@ Json::Value TrackedObjectBBox::JsonValue() const
root["scale_x"] = scale_x.JsonValue();
root["scale_y"] = scale_y.JsonValue();
root["rotation"] = rotation.JsonValue();
root["visible"] = visible.JsonValue();

// return JsonValue
return root;
Expand Down Expand Up @@ -385,7 +386,9 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root)
scale_y.SetJsonValue(root["scale_y"]);
if (!root["rotation"].isNull())
rotation.SetJsonValue(root["rotation"]);

if (!root["visible"].isNull())
visible.SetJsonValue(root["visible"]);

return;
}

Expand All @@ -400,9 +403,6 @@ Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const
// Add the ID of this object to the JSON object
root["box_id"] = add_property_json("Box ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);

// Add a boolean property to inform if the object has data for the requested frame
root["visible"] = add_property_json("Visible", ExactlyContains(requested_frame), "bool", "", NULL, -1, -1, true, requested_frame);

// Add the data of given frame bounding-box to the JSON object
root["x1"] = add_property_json("X1", box.cx-(box.width/2), "float", "", NULL, 0.0, 1.0, false, requested_frame);
root["y1"] = add_property_json("Y1", box.cy-(box.height/2), "float", "", NULL, 0.0, 1.0, false, requested_frame);
Expand All @@ -415,6 +415,7 @@ Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const
root["scale_x"] = add_property_json("Scale (Width)", scale_x.GetValue(requested_frame), "float", "", &scale_x, -1.0, 1.0, false, requested_frame);
root["scale_y"] = add_property_json("Scale (Height)", scale_y.GetValue(requested_frame), "float", "", &scale_y, -1.0, 1.0, false, requested_frame);
root["rotation"] = add_property_json("Rotation", rotation.GetValue(requested_frame), "float", "", &rotation, 0, 360, false, requested_frame);
root["visible"] = add_property_json("Visible", visible.GetValue(requested_frame), "int", "", &visible, 0, 1, false, requested_frame);

// Return formatted string
return root;
Expand Down
1 change: 0 additions & 1 deletion src/TrackedObjectBBox.h
Expand Up @@ -157,7 +157,6 @@ namespace openshot
class TrackedObjectBBox : public TrackedObjectBase
{
private:
bool visible;
Fraction BaseFps;
double TimeScale;

Expand Down
6 changes: 4 additions & 2 deletions src/TrackedObjectBase.cpp
Expand Up @@ -37,13 +37,15 @@
namespace openshot{

// Blank constructor
TrackedObjectBase::TrackedObjectBase(){
TrackedObjectBase::TrackedObjectBase() : visible(1.0)
{
// Initializes the id as "None"
id = "None";
}

// Default constructor
TrackedObjectBase::TrackedObjectBase(std::string _id){
TrackedObjectBase::TrackedObjectBase(std::string _id) : visible(1.0)
{
Id(_id);
}
}
4 changes: 4 additions & 0 deletions src/TrackedObjectBase.h
Expand Up @@ -40,6 +40,7 @@
#include "Exceptions.h"
#include "Fraction.h"
#include "Coordinate.h"
#include "KeyFrame.h"
#include "Point.h"
#include "Json.h"
#include "ClipBase.h"
Expand All @@ -57,9 +58,12 @@ namespace openshot {
private:
std::string id;
ClipBase* parentClip;


public:

Keyframe visible;

/// Blank constructor
TrackedObjectBase();

Expand Down
6 changes: 4 additions & 2 deletions src/effects/ObjectDetection.cpp
Expand Up @@ -104,8 +104,8 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
std::shared_ptr<TrackedObjectBBox> trackedObject = std::static_pointer_cast<TrackedObjectBBox>(trackedObject_it->second);

// Check if the tracked object has data for this frame
if (trackedObject->Contains(frame_number)){
if (trackedObject->Contains(frame_number) && trackedObject->visible.GetValue(frame_number) == 1)
{
// Get the bounding-box of given frame
BBox trackedBox = trackedObject->GetBox(frame_number);
cv::Rect2d box(
Expand Down Expand Up @@ -316,6 +316,7 @@ Json::Value ObjectDetection::JsonValue() const {
root["scale_x"] = selectedObjectJSON["scale_x"];
root["scale_y"] = selectedObjectJSON["scale_y"];
root["rotation"] = selectedObjectJSON["rotation"];
root["visible"] = selectedObjectJSON["visible"];
}

// return JsonValue
Expand Down Expand Up @@ -374,6 +375,7 @@ void ObjectDetection::SetJsonValue(const Json::Value root) {
selectedObjectJSON["scale_x"] = root["scale_x"];
selectedObjectJSON["scale_y"] = root["scale_y"];
selectedObjectJSON["rotation"] = root["rotation"];
selectedObjectJSON["visible"] = root["visible"];
if (!selectedObjectJSON.isNull()){
auto selectedObject = trackedObjects.at(selectedObjectIndex);
if (selectedObject)
Expand Down
5 changes: 3 additions & 2 deletions src/effects/Tracker.cpp
Expand Up @@ -96,7 +96,7 @@ std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> frame, int64_t f
if(!frame_image.empty())
{
// Check if track data exists for the requested frame
if (trackedData->Contains(frame_number))
if (trackedData->Contains(frame_number) && trackedData->visible.GetValue(frame_number) == 1)
{
// Get the width and height of the image
float fw = frame_image.size().width;
Expand Down Expand Up @@ -181,6 +181,7 @@ Json::Value Tracker::JsonValue() const {
root["scale_x"] = trackedObjectJSON["scale_x"];
root["scale_y"] = trackedObjectJSON["scale_y"];
root["rotation"] = trackedObjectJSON["rotation"];
root["visible"] = trackedObjectJSON["visible"];
}

// return JsonValue
Expand Down Expand Up @@ -256,6 +257,7 @@ void Tracker::SetJsonValue(const Json::Value root) {
trackedObjectJSON["scale_x"] = root["scale_x"];
trackedObjectJSON["scale_y"] = root["scale_y"];
trackedObjectJSON["rotation"] = root["rotation"];
trackedObjectJSON["visible"] = root["visible"];
if (!trackedObjectJSON.isNull())
trackedObject.second->SetJsonValue(trackedObjectJSON);
}
Expand Down Expand Up @@ -288,7 +290,6 @@ std::string Tracker::PropertiesJSON(int64_t requested_frame) const {
}

// Append effect's properties
root["name"] = add_property_json("Tracker", 0.0, "string", "", NULL, -1, -1, true, requested_frame);
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
Expand Down

0 comments on commit 2e47325

Please sign in to comment.