Skip to content

Commit

Permalink
Protecting ObjectDetection when no object is found
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Apr 8, 2021
1 parent c55efd1 commit 6b6b6d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/TrackedObjectBBox.cpp
Expand Up @@ -388,7 +388,7 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root)

// Set the id of the child clip
// Does not allow to link to the parent clip
if (!root["child_clip_id"].isNull()){
if (!root["child_clip_id"].isNull() && root["box_id"].asString() != "None"){
Clip* parentClip = (Clip *) ParentClip();

if(parentClip && (root["child_clip_id"].asString() != parentClip->Id())){
Expand Down
28 changes: 17 additions & 11 deletions src/effects/ObjectDetection.cpp
Expand Up @@ -309,11 +309,13 @@ Json::Value ObjectDetection::JsonValue() const {
}

// Add the selected object Json to root
auto selectedObject = trackedObjects.at(selectedObjectIndex);
if (selectedObject){
Json::Value selectedObjectJSON = selectedObject->JsonValue();
for (auto const& key : selectedObjectJSON.getMemberNames())
root[key] = selectedObjectJSON[key];
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
Expand Down Expand Up @@ -366,9 +368,11 @@ void ObjectDetection::SetJsonValue(const Json::Value root) {
}

// Set the selected object's properties
auto selectedObject = trackedObjects.at(selectedObjectIndex);
if (selectedObject)
selectedObject->SetJsonValue(root);
if(trackedObjects.count(selectedObjectIndex) != 0){
auto selectedObject = trackedObjects.at(selectedObjectIndex);
if (selectedObject)
selectedObject->SetJsonValue(root);
}
}

// Get all properties for a specific frame
Expand All @@ -378,9 +382,11 @@ std::string ObjectDetection::PropertiesJSON(int64_t requested_frame) const {
Json::Value root;

// Add the selected object Json to root
auto selectedObject = trackedObjects.at(selectedObjectIndex);
if (selectedObject)
root = selectedObject->PropertiesJSON(requested_frame);
if(trackedObjects.count(selectedObjectIndex) != 0){
auto selectedObject = trackedObjects.at(selectedObjectIndex);
if (selectedObject)
root = selectedObject->PropertiesJSON(requested_frame);
}

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);
Expand Down

0 comments on commit 6b6b6d5

Please sign in to comment.