Use regular expressions for plate matching (#14727)

This commit is contained in:
Josh Hawkins
2024-11-01 18:43:21 -05:00
committed by Nicolas Mowen
parent 90916879b7
commit 1ab061effd
5 changed files with 26 additions and 25 deletions

View File

@@ -3,6 +3,7 @@
import base64
import logging
import os
import re
import threading
from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path
@@ -23,7 +24,7 @@ from frigate.comms.events_updater import EventEndSubscriber, EventUpdateSubscrib
from frigate.comms.inter_process import InterProcessRequestor
from frigate.config import FrigateConfig
from frigate.const import CLIPS_DIR, FRIGATE_LOCALHOST, UPDATE_EVENT_DESCRIPTION
from frigate.embeddings.alpr.alpr import LicensePlateRecognition
from frigate.embeddings.lpr.lpr import LicensePlateRecognition
from frigate.events.types import EventTypeEnum
from frigate.genai import get_genai_client
from frigate.models import Event
@@ -683,13 +684,16 @@ class EmbeddingMaintainer(threading.Thread):
)
return
# Determine subLabel based on known plates
# Determine subLabel based on known plates, use regex matching
# Default to the detected plate, use label name if there's a match
sub_label = top_plate
for label, plates in self.lpr_config.known_plates.items():
if top_plate in plates:
sub_label = label
break
sub_label = next(
(
label
for label, plates in self.lpr_config.known_plates.items()
if any(re.match(f"^{plate}$", top_plate) for plate in plates)
),
top_plate,
)
# Send the result to the API
resp = requests.post(