ALPR Mod - Display Custom Name for Known Plates

Feb 1, 2022
5
2
Redmond
This was an incredibly simple modification to the Code Project AI ALPR module to override known plates with a custom name. This is useful if you're getting mobile alerts so you don't need to know that the in-law's plate number is 05DE1W, instead the alert will read "In-Laws", or whatever other name you prescribe.

Add a "known_plates.py" file to the ALPR module typically located "C:\Program Files\CodeProject\AI\modules\ALPR". Open this new file with a text editor and add the following:
# lines that start with a '#' are comments
# Add as may rows as you have known plates
# be sure to end each entry with a comma
# We are creating a python dictionary,
# google it to learn more.

KNOWN_PLATES = {
# "Plate Number" : "Friendly Name",
"05DE1W" : "Mother in-law",
}
Once this file is created and populated you can modify the ALPR.py file. Start by adding this line to the top of the file to import our known plates dictionary.
from known_plates import KNOWN_PLATES

Then we're going to modify the returned data to provide either a lookup from our known plates or the plate number if the plate is not in the known plates dictionary. There are 2 lines to modify, mine were on lines 311 and 312 after adding the import statement above. Essentially we're going to replace the <label> variable with KNOWN_PLATES.get(label, label). This will tell the code to look up the friendly name in our known plates dictionary using the found plate, what the code calls label, and if it doesn't exist just return the label (plate number). You can see below the modifications were made to the "label" and "plate" items within the "detection" dictionary. The other items are unchanged, I just included them for completeness.
detection = {
"confidence": confidence,
"label": "Plate: " + KNOWN_PLATES.get(label, label),
"plate": KNOWN_PLATES.get(label, label),
"x_min": plate_rect.left,
"y_min": plate_rect.top,
"x_max": plate_rect.right,
"y_max": plate_rect.bottom
}

Once these changes are made you'll need to restart the ALPR module on the CodeProject.AI server by going to it here (or where ever you're running it per Blue Iris's main AI config settings page), scrolling down to the License Plate Reader module and restarting it. You'll also need to restart it every time you add a new known plate.

End Result:

I hope this is useful to others!
 

Attachments

  • Screenshot 2024-12-07 222801.png
    Screenshot 2024-12-07 222801.png
    702.6 KB · Views: 13