From a55e265480ee4b0d1b1e72ffddd918b143e538e9 Mon Sep 17 00:00:00 2001 From: Conner Vieira Date: Sun, 22 Oct 2023 19:47:15 -0400 Subject: [PATCH] Added configuration for realtime object detection --- TODO.md | 1 + config.json | 6 +++++- main.py | 25 +++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index d725eee..e58be9e 100644 --- a/TODO.md +++ b/TODO.md @@ -66,6 +66,7 @@ These are the features actively planned for Predator and are likely to be added - [X] Test updated license plate validation in pre-recorded mode. - [X] Test updated license plate validation in real-time mode. - [X] Add Phantom alert handling to updated ALPR stream. + - [ ] Display prominent alerts of the ALPR process fails. - [ ] Complete OpenCV dashcam recording. - [X] Improve the efficiency of GPS location requests when many requests are made in quick succession. - [ ] Test that improved GPS location querying behaves as expected. diff --git a/config.json b/config.json index 7683b81..c9687e8 100755 --- a/config.json +++ b/config.json @@ -27,7 +27,7 @@ "debugging_output": false }, "object_recognition": { - "enabled": false + "enabled": true }, "modes": { "auto_start": "", @@ -75,6 +75,10 @@ "clearing": true } }, + "object_recognition": { + "enabled": true, + "video_still_path": "/dev/shm/phantom-webcam.jpg" + }, "gps": { "enabled": false, "alpr_location_tagging": true diff --git a/main.py b/main.py index c6d8135..bf907dc 100644 --- a/main.py +++ b/main.py @@ -1318,18 +1318,19 @@ if (config["realtime"]["interface"]["display"]["output_level"] >= 3): # Only display this status message if the output level indicates to do so. print("Running object recognition...") - image = cv2.imread(config["realtime"]["object_recognition"]["enabled"]) # Load the frame. - object_recognition_bounding_box, object_recognition_labels, object_recognition_confidence = cv.detect_common_objects(image) # Anaylze the image. - objects_identified = str(object_recognition_labels) # Convert the list of objects identified into a plain string. - if (objects_identified != "[]"): # Check to see that there were actually identified objects. - if (config["realtime"]["interface"]["display"]["output_level"] >= 2): # Only display this status message if the output level indicates to do so. - print("Objects identified: " + objects_identified) - export_data = str(round(time.time()*10)/10) + "," + objects_identified + "\n" # Add the timestamp to the export data, followed by the object's detected, followed by a line break to prepare for the next entry to be added later. - if (save_real_time_object_recognition == True): # Check to make sure the user has configured Predator to save recognized objects to disk. - add_to_file(root + "/real_time_object_detection.csv", export_data, silence_file_saving) # Add the export data to the end of the file and write it to disk. - - if (config["realtime"]["interface"]["display"]["output_level"] >= 3): # Only display this status message if the output level indicates to do so. - print("Done\n----------") + if (os.path.exists(video_still_path) == True): + image = cv2.imread(config["realtime"]["object_recognition"]["video_still_path"]) # Load the frame. + object_recognition_bounding_box, object_recognition_labels, object_recognition_confidence = cv.detect_common_objects(image) # Anaylze the image. + objects_identified = str(object_recognition_labels) # Convert the list of objects identified into a plain string. + if (objects_identified != "[]"): # Check to see that there were actually identified objects. + if (config["realtime"]["interface"]["display"]["output_level"] >= 2): # Only display this status message if the output level indicates to do so. + print("Objects identified: " + objects_identified) + export_data = str(round(time.time()*10)/10) + "," + objects_identified + "\n" # Add the timestamp to the export data, followed by the object's detected, followed by a line break to prepare for the next entry to be added later. + if (save_real_time_object_recognition == True): # Check to make sure the user has configured Predator to save recognized objects to disk. + add_to_file(root + "/real_time_object_detection.csv", export_data, silence_file_saving) # Add the export data to the end of the file and write it to disk. + + if (config["realtime"]["interface"]["display"]["output_level"] >= 3): # Only display this status message if the output level indicates to do so. + print("Done\n----------")