From c6ce5b0e16e3f4246d00411465ad2cccda67e71a Mon Sep 17 00:00:00 2001 From: Brenno Date: Sat, 8 May 2021 20:24:39 -0300 Subject: [PATCH] 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);