diff --git a/src/CVObjectDetection.cpp b/src/CVObjectDetection.cpp index 398411d1..959c37bc 100644 --- a/src/CVObjectDetection.cpp +++ b/src/CVObjectDetection.cpp @@ -85,8 +85,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++) diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 71642f6a..cc8be187 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 d84d8841..13093475 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -371,6 +371,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}); } @@ -458,21 +461,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 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]; - } + // add object json + objects[trackedObject.second->Id()] = trackedObjectJSON; } + root["objects"] = objects; // return JsonValue return root; @@ -484,7 +479,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){ @@ -544,13 +545,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 @@ -559,12 +553,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); diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index 1e67ef52..01537f77 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -60,6 +60,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}); } @@ -74,6 +75,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}); } @@ -265,17 +267,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; @@ -334,18 +334,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 { @@ -353,8 +362,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);