From c6ce5b0e16e3f4246d00411465ad2cccda67e71a Mon Sep 17 00:00:00 2001 From: Brenno Date: Sat, 8 May 2021 20:24:39 -0300 Subject: [PATCH 1/4] Key "objects" in Json hold a dict of tracked objects --- src/TrackedObjectBBox.cpp | 8 +------ src/effects/ObjectDetection.cpp | 40 ++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 71642f6a8..cc8be1872 100644 --- a/src/TrackedObjectBBox.cpp +++ b/src/TrackedObjectBBox.cpp @@ -382,25 +382,19 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root) if (!root["BaseFPS"]["den"].isNull()) BaseFps.den = (int)root["BaseFPS"]["den"].asInt(); } - // Set the TimeScale by the given JSON object if (!root["TimeScale"].isNull()) { double scale = (double)root["TimeScale"].asDouble(); this->ScalePoints(scale); } - // Set the protobuf data path by the given JSON object if (!root["protobuf_data_path"].isNull()) protobufDataPath = root["protobuf_data_path"].asString(); - // Set the id of the child clip if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != ""){ Clip* parentClip = (Clip *) ParentClip(); - - if(parentClip && (root["child_clip_id"].asString() != parentClip->Id())){ - ChildClipId(root["child_clip_id"].asString()); - } + ChildClipId(root["child_clip_id"].asString()); } // Set the Keyframes by the given JSON object diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index 19ef8ac97..6141ba550 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -369,6 +369,9 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){ ClipBase* parentClip = this->ParentClip(); trackedObjPtr->ParentClip(parentClip); + // Create a temp ID. This ID is necessary to initialize the object_id Json list + // this Id will be replaced by the one created in the UI + trackedObjPtr->Id(std::to_string(objectId)); trackedObjects.insert({objectId, trackedObjPtr}); } @@ -456,11 +459,13 @@ Json::Value ObjectDetection::JsonValue() const { root["display_box_text"] = display_box_text.JsonValue(); // Add tracked object's IDs to root - root["objects_id"] = Json::Value(Json::arrayValue); + Json::Value objects; for (auto const& trackedObject : trackedObjects){ Json::Value trackedObjectJSON = trackedObject.second->JsonValue(); - root["objects_id"].append(trackedObject.second->Id()); + // add object json + objects[trackedObject.second->Id()] = trackedObjectJSON; } + root["objects"] = objects; // Add the selected object Json to root if(trackedObjects.count(selectedObjectIndex) != 0){ @@ -482,7 +487,6 @@ void ObjectDetection::SetJson(const std::string value) { // Parse JSON string into JSON objects try { - std::cout<<"entrou no objectDetection SetJson \n"<SetJsonValue(root["objects"][obj_id]); + } + } + } + // Set the tracked object's ids if (!root["objects_id"].isNull()){ for (auto const& trackedObject : trackedObjects){ @@ -542,13 +553,6 @@ void ObjectDetection::SetJsonValue(const Json::Value root) { trackedObject.second->SetJsonValue(trackedObjectJSON); } } - - // Set the selected object's properties - if(trackedObjects.count(selectedObjectIndex) != 0){ - auto selectedObject = trackedObjects.at(selectedObjectIndex); - if (selectedObject) - selectedObject->SetJsonValue(root); - } } // Get all properties for a specific frame @@ -557,12 +561,16 @@ std::string ObjectDetection::PropertiesJSON(int64_t requested_frame) const { // Generate JSON properties list Json::Value root; - // Add the selected object Json to root + Json::Value objects; if(trackedObjects.count(selectedObjectIndex) != 0){ auto selectedObject = trackedObjects.at(selectedObjectIndex); - if (selectedObject) - root = selectedObject->PropertiesJSON(requested_frame); + if (selectedObject){ + Json::Value trackedObjectJSON = selectedObject->PropertiesJSON(requested_frame); + // add object json + objects[selectedObject->Id()] = trackedObjectJSON; + } } + root["objects"] = objects; root["selected_object_index"] = add_property_json("Selected Object", selectedObjectIndex, "int", "", NULL, 0, 200, false, requested_frame); root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame); From 7eb23a9f1965341f9ac0358b42bdbc91c95b1a09 Mon Sep 17 00:00:00 2001 From: Brenno Date: Tue, 11 May 2021 11:34:30 -0300 Subject: [PATCH 2/4] Removed unnecessary Json tags --- src/effects/ObjectDetection.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index 6141ba550..61b21c45d 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -467,16 +467,6 @@ Json::Value ObjectDetection::JsonValue() const { } root["objects"] = objects; - // Add the selected object Json to root - if(trackedObjects.count(selectedObjectIndex) != 0){ - auto selectedObject = trackedObjects.at(selectedObjectIndex); - if (selectedObject){ - Json::Value selectedObjectJSON = selectedObject->JsonValue(); - for (auto const& key : selectedObjectJSON.getMemberNames()) - root[key] = selectedObjectJSON[key]; - } - } - // return JsonValue return root; } From e45b81bd7bdf40ada605f81a8be08f64bc7742b6 Mon Sep 17 00:00:00 2001 From: Brenno Date: Tue, 11 May 2021 12:12:35 -0300 Subject: [PATCH 3/4] Updated Json communication of Tracker effect --- src/effects/ObjectDetection.cpp | 2 +- src/effects/Tracker.cpp | 50 +++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index 61b21c45d..30505cfb5 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -498,7 +498,7 @@ void ObjectDetection::SetJsonValue(const Json::Value root) { protobuf_data_path = root["protobuf_data_path"].asString(); if(!LoadObjDetectdData(protobuf_data_path)){ - throw InvalidFile("Invalid protobuf data path"); + throw InvalidFile("Invalid protobuf data path", ""); protobuf_data_path = ""; } } diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index d04d7e30d..a5aa511dd 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -54,6 +54,7 @@ Tracker::Tracker(std::string clipTrackerDataPath) trackedData->LoadBoxData(clipTrackerDataPath); ClipBase* parentClip = this->ParentClip(); trackedData->ParentClip(parentClip); + trackedData->Id(std::to_string(0)); // Insert TrackedObject with index 0 to the trackedObjects map trackedObjects.insert({0, trackedData}); } @@ -68,6 +69,7 @@ Tracker::Tracker() trackedData = std::make_shared(trackedDataObject); ClipBase* parentClip = this->ParentClip(); trackedData->ParentClip(parentClip); + trackedData->Id(std::to_string(0)); // Insert TrackedObject with index 0 to the trackedObjects map trackedObjects.insert({0, trackedData}); } @@ -260,17 +262,15 @@ Json::Value Tracker::JsonValue() const { root["BaseFPS"]["num"] = BaseFPS.num; root["BaseFPS"]["den"] = BaseFPS.den; root["TimeScale"] = this->TimeScale; - root["objects_id"] = Json::Value(Json::arrayValue); // Add trackedObjects IDs to JSON - for (auto const& trackedObject : trackedObjects){ - // Get the trackedObject JSON - Json::Value trackedObjectJSON = trackedObject.second->JsonValue(); - root["objects_id"].append(trackedObject.second->Id()); - // Save the trackedObject JSON on root - for (auto const& key : trackedObjectJSON.getMemberNames()) - root[key] = trackedObjectJSON[key]; - } + Json::Value objects; + for (auto const& trackedObject : trackedObjects){ + Json::Value trackedObjectJSON = trackedObject.second->JsonValue(); + // add object json + objects[trackedObject.second->Id()] = trackedObjectJSON; + } + root["objects"] = objects; // return JsonValue return root; @@ -329,18 +329,27 @@ void Tracker::SetJsonValue(const Json::Value root) { } } - // Set the tracked object's properties - for (auto const& trackedObject : trackedObjects){ - Json::Value trackedObjectJSON = root; - if (!root["objects_id"].isNull()) - trackedObjectJSON["box_id"] = root["objects_id"][trackedObject.first].asString(); - trackedObject.second->SetJsonValue(trackedObjectJSON); + if (!root["objects"].isNull()){ + for (auto const& trackedObject : trackedObjects){ + std::string obj_id = std::to_string(trackedObject.first); + if(!root["objects"][obj_id].isNull()){ + trackedObject.second->SetJsonValue(root["objects"][obj_id]); + } + } } + + // Set the tracked object's ids + if (!root["objects_id"].isNull()){ + for (auto const& trackedObject : trackedObjects){ + Json::Value trackedObjectJSON; + trackedObjectJSON["box_id"] = root["objects_id"][trackedObject.first].asString(); + trackedObject.second->SetJsonValue(trackedObjectJSON); + } + } return; } - // Get all properties for a specific frame std::string Tracker::PropertiesJSON(int64_t requested_frame) const { @@ -348,8 +357,13 @@ std::string Tracker::PropertiesJSON(int64_t requested_frame) const { Json::Value root; // Add trackedObject properties to JSON - for (auto const& trackedObject : trackedObjects) - root = trackedObject.second->PropertiesJSON(requested_frame); + Json::Value objects; + for (auto const& trackedObject : trackedObjects){ + Json::Value trackedObjectJSON = trackedObject.second->PropertiesJSON(requested_frame); + // add object json + objects[trackedObject.second->Id()] = trackedObjectJSON; + } + root["objects"] = objects; // Append effect's properties root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame); From e2b51da44227366b9f7460f31d5105b1d440a1d9 Mon Sep 17 00:00:00 2001 From: Brenno Date: Wed, 19 May 2021 11:45:09 -0300 Subject: [PATCH 4/4] Fixed missing detection in the first frame --- src/CVObjectDetection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CVObjectDetection.cpp b/src/CVObjectDetection.cpp index bab072770..ac0ca1014 100644 --- a/src/CVObjectDetection.cpp +++ b/src/CVObjectDetection.cpp @@ -81,8 +81,8 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, size_t frame_number; if(!process_interval || end <= 1 || end-start == 0){ // Get total number of frames in video - start = (int)(video.Start() * video.Reader()->info.fps.ToFloat()) + 1; - end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1; + start = (int)(video.Start() * video.Reader()->info.fps.ToFloat()); + end = (int)(video.End() * video.Reader()->info.fps.ToFloat()); } for (frame_number = start; frame_number <= end; frame_number++)