Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
feat: Update showUnseenObjects flag and add saveDetectionsPath field …
Browse files Browse the repository at this point in the history
…to FilterData struct
  • Loading branch information
royshil committed May 29, 2024
1 parent df5a54b commit c18a1a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"name": "obs-detect",
"displayName": "OBS Object Detection plugin",
"version": "0.0.2",
"version": "0.0.3",
"author": "Roy Shilkrot",
"website": "https://github.com/occ-ai/obs-detect",
"email": "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ MaxUnseenFrames="Max Unseen Frames"
ExternalModel="External Model"
ModelPath="Model Path"
ShowUnseenObjects="Show Currently Undetected Objects"
SaveDetectionsPath="Save Detections Path"
1 change: 1 addition & 0 deletions src/FilterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct filter_data {
int lastDetectedObjectId;
bool sortTracking;
bool showUnseenObjects;
std::string saveDetectionsPath;

// create SORT tracker
Sort tracker;
Expand Down
33 changes: 32 additions & 1 deletion src/detect-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static bool enable_advanced_settings(obs_properties_t *ppts, obs_property_t *p,
const bool enabled = obs_data_get_bool(settings, "advanced");

for (const char *prop_name :
{"threshold", "useGPU", "numThreads", "model_size", "detected_object"}) {
{"threshold", "useGPU", "numThreads", "model_size", "detected_object", "sort_tracking",
"max_unseen_frames", "show_unseen_objects", "save_detections_path"}) {
p = obs_properties_get(ppts, prop_name);
obs_property_set_visible(p, enabled);
}
Expand Down Expand Up @@ -266,6 +267,11 @@ obs_properties_t *detect_filter_properties(void *data)
// add option to show unseen objects
obs_properties_add_bool(props, "show_unseen_objects", obs_module_text("ShowUnseenObjects"));

// add file path for saving detections
obs_properties_add_path(props, "save_detections_path",
obs_module_text("SaveDetectionsPath"), OBS_PATH_FILE_SAVE,
"JSON file (*.json);;All files (*.*)", nullptr);

/* GPU, CPU and performance Props */
obs_property_t *p_use_gpu =
obs_properties_add_list(props, "useGPU", obs_module_text("InferenceDevice"),
Expand Down Expand Up @@ -381,6 +387,7 @@ void detect_filter_defaults(obs_data_t *settings)
obs_data_set_default_double(settings, "zoom_factor", 0.0);
obs_data_set_default_double(settings, "zoom_speed_factor", 0.05);
obs_data_set_default_string(settings, "zoom_object", "single");
obs_data_set_default_string(settings, "save_detections_path", "");
}

void detect_filter_update(void *data, obs_data_t *settings)
Expand Down Expand Up @@ -408,6 +415,7 @@ void detect_filter_update(void *data, obs_data_t *settings)
tf->tracker.setMaxUnseenFrames(maxUnseenFrames);
}
tf->showUnseenObjects = obs_data_get_bool(settings, "show_unseen_objects");
tf->saveDetectionsPath = obs_data_get_string(settings, "save_detections_path");

// check if tracking state has changed
if (tf->trackingEnabled != newTrackingEnabled) {
Expand Down Expand Up @@ -779,6 +787,29 @@ void detect_filter_video_tick(void *data, float seconds)
objects.end());
}

if (!tf->saveDetectionsPath.empty()) {
std::ofstream detectionsFile(tf->saveDetectionsPath);
if (detectionsFile.is_open()) {
nlohmann::json j;
for (const edgeyolo_cpp::Object &obj : objects) {
nlohmann::json obj_json;
obj_json["label"] = obj.label;
obj_json["confidence"] = obj.prob;
obj_json["rect"] = {{"x", obj.rect.x},
{"y", obj.rect.y},
{"width", obj.rect.width},
{"height", obj.rect.height}};
obj_json["id"] = obj.id;
j.push_back(obj_json);
}
detectionsFile << j.dump(4);
detectionsFile.close();
} else {
obs_log(LOG_ERROR, "Failed to open file for writing detections: %s",
tf->saveDetectionsPath.c_str());
}
}

if (tf->preview || tf->maskingEnabled) {
if (tf->preview && objects.size() > 0) {
edgeyolo_cpp::utils::draw_objects(frame, objects, tf->classNames);
Expand Down

0 comments on commit c18a1a9

Please sign in to comment.