diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index df60afd7..6e1ae97c 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -362,11 +362,14 @@ void ObjectDetection::SetJsonValue(const Json::Value root) EffectBase::SetJsonValue(root); // If a protobuf path is provided, load & prefix IDs - if (!root["protobuf_data_path"].isNull() && protobuf_data_path.empty()) { - protobuf_data_path = root["protobuf_data_path"].asString(); - if (!LoadObjDetectdData(protobuf_data_path)) { - throw InvalidFile("Invalid protobuf data path", ""); - } + if (!root["protobuf_data_path"].isNull()) { + std::string new_path = root["protobuf_data_path"].asString(); + if (protobuf_data_path != new_path || trackedObjects.empty()) { + protobuf_data_path = new_path; + if (!LoadObjDetectdData(protobuf_data_path)) { + throw InvalidFile("Invalid protobuf data path", ""); + } + } } // Selected index, thresholds, UI flags, filters, etc. diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index d485f903..2776ab7a 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -220,22 +220,25 @@ void Tracker::SetJsonValue(const Json::Value root) { TimeScale = root["TimeScale"].asDouble(); } - if (!root["protobuf_data_path"].isNull() && protobuf_data_path.empty()) { - protobuf_data_path = root["protobuf_data_path"].asString(); - if (!trackedData->LoadBoxData(protobuf_data_path)) { - std::clog << "Invalid protobuf data path " << protobuf_data_path << '\n'; - protobuf_data_path.clear(); - } - else { - // prefix "-" for each entry - for (auto& kv : trackedObjects) { - auto idx = kv.first; - auto ptr = kv.second; - if (ptr) { - std::string prefix = this->Id(); - if (!prefix.empty()) - prefix += "-"; - ptr->Id(prefix + std::to_string(idx)); + if (!root["protobuf_data_path"].isNull()) { + std::string new_path = root["protobuf_data_path"].asString(); + if (protobuf_data_path != new_path || trackedData->GetLength() == 0) { + protobuf_data_path = new_path; + if (!trackedData->LoadBoxData(protobuf_data_path)) { + std::clog << "Invalid protobuf data path " << protobuf_data_path << '\n'; + protobuf_data_path.clear(); + } + else { + // prefix "-" for each entry + for (auto& kv : trackedObjects) { + auto idx = kv.first; + auto ptr = kv.second; + if (ptr) { + std::string prefix = this->Id(); + if (!prefix.empty()) + prefix += "-"; + ptr->Id(prefix + std::to_string(idx)); + } } } }