From f328ced95f8c881af0b1f4ba2bf9c316b4e6f9ed Mon Sep 17 00:00:00 2001 From: Conner Vieira Date: Sat, 29 Apr 2023 14:11:41 -0400 Subject: [PATCH] Adjusted license plate logging behavior --- CHANGELOG.md | 1 + main.py | 35 ++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03039d2..7110915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -325,3 +325,4 @@ This update refines Predator's functionality, and focuses its purpose back on li - Object recognition library importing has been improved. - The configuration value to globally disable object recognition has been removed, and replaced with a single control that enables object recognition. - Fixed an issue where dashcam recording would cause a crash when displaying the process start message. +- Entries are now only added to the license plate history log file if one or more license plates were detected. diff --git a/main.py b/main.py index a6b2131..3c1c4b1 100644 --- a/main.py +++ b/main.py @@ -1546,31 +1546,32 @@ # Save detected license plates to file. if (config["realtime"]["saving"]["license_plates"] != ""): # Check to see if license plate history saving is enabled. debug_message("Saving license plate history") - current_time = time.time() # Get the current timestamp. + if (len(all_current_plate_guesses) > 0): # Only save the license plate history for this round if 1 or more plates were detected. + current_time = time.time() # Get the current timestamp. - plate_log[current_time] = {} # Initialize an entry in the plate history log using the current time. + plate_log[current_time] = {} # Initialize an entry in the plate history log using the current time. - if (config["realtime"]["gps"]["alpr_location_tagging"] == True): # Check to see if the configuration value for geotagging license plate detections has been enabled. - if (config["realtime"]["gps"]["enabled"] == True): # Check to see if GPS functionality is enabled. - current_location = get_gps_location() # Get the current location. - else: - current_location = [0.0, 0.0] # Grab a placeholder for the current location, since GPS functionality is disabled. + if (config["realtime"]["gps"]["alpr_location_tagging"] == True): # Check to see if the configuration value for geotagging license plate detections has been enabled. + if (config["realtime"]["gps"]["enabled"] == True): # Check to see if GPS functionality is enabled. + current_location = get_gps_location() # Get the current location. + else: + current_location = [0.0, 0.0] # Grab a placeholder for the current location, since GPS functionality is disabled. - plate_log[current_time]["location"] = {"lat": current_location[0],"lon": current_location[1]} # Add the current location to the plate history log entry. + plate_log[current_time]["location"] = {"lat": current_location[0],"lon": current_location[1]} # Add the current location to the plate history log entry. - plate_log[current_time]["plates"] = {} + plate_log[current_time]["plates"] = {} - for plate in all_current_plate_guesses: # Iterate though each plate detected this round. - plate_log[current_time]["plates"][plate] = {"alerts": [], "guesses": {}} # Initialize this plate in the plate log. - for guess in all_current_plate_guesses[plate]: # Iterate through each guess in this plate. - if (guess in active_alerts): # Check to see if this guess matches one of the active alerts. - plate_log[current_time]["plates"][plate]["alerts"].append(active_alerts[guess]["rule"]) # Add the rule that triggered the alert to a separate list. - plate_log[current_time]["plates"][plate]["guesses"][guess] = all_current_plate_guesses[plate][guess] # Add this guess to the log, with its confidence level. + for plate in all_current_plate_guesses: # Iterate though each plate detected this round. + plate_log[current_time]["plates"][plate] = {"alerts": [], "guesses": {}} # Initialize this plate in the plate log. + for guess in all_current_plate_guesses[plate]: # Iterate through each guess in this plate. + if (guess in active_alerts): # Check to see if this guess matches one of the active alerts. + plate_log[current_time]["plates"][plate]["alerts"].append(active_alerts[guess]["rule"]) # Add the rule that triggered the alert to a separate list. + plate_log[current_time]["plates"][plate]["guesses"][guess] = all_current_plate_guesses[plate][guess] # Add this guess to the log, with its confidence level. - plate_log[current_time]["plates"][plate]["alerts"] = list(dict.fromkeys(plate_log[current_time]["plates"][plate]["alerts"])) # De-duplicate the 'alerts' list for this plate. + plate_log[current_time]["plates"][plate]["alerts"] = list(dict.fromkeys(plate_log[current_time]["plates"][plate]["alerts"])) # De-duplicate the 'alerts' list for this plate. - save_to_file(plate_log_file_location, json.dumps(plate_log), True) # Save the modified plate log to the disk as JSON data. + save_to_file(plate_log_file_location, json.dumps(plate_log), True) # Save the modified plate log to the disk as JSON data.