define a format option and adjust thresholds

This commit is contained in:
Josh Hawkins 2025-02-14 15:42:08 -06:00
parent 0b65137831
commit 791a8520f9

View File

@ -282,16 +282,27 @@ class LicensePlateProcessor(RealTimeProcessorApi):
average_confidences[original_idx] = average_confidence average_confidences[original_idx] = average_confidence
areas[original_idx] = area areas[original_idx] = area
# Filter out plates that have a length of less than 3 characters # Filter out plates that have a length of less than min_plate_length characters
# or that don't match the expected format (if defined)
# Sort by area, then by plate length, then by confidence all desc # Sort by area, then by plate length, then by confidence all desc
sorted_data = sorted( filtered_data = []
[ for plate, conf, area in zip(license_plates, average_confidences, areas):
(plate, conf, area) if len(plate) < self.lpr_config.min_plate_length:
for plate, conf, area in zip( logger.debug(
license_plates, average_confidences, areas f"Filtered out '{plate}' due to length ({len(plate)} < {self.lpr_config.min_plate_length})"
) )
if len(plate) >= self.lpr_config.min_plate_length continue
],
if self.lpr_config.format and not re.fullmatch(
self.lpr_config.format, plate
):
logger.debug(f"Filtered out '{plate}' due to format mismatch")
continue
filtered_data.append((plate, conf, area))
sorted_data = sorted(
filtered_data,
key=lambda x: (x[2], len(x[0]), x[1]), key=lambda x: (x[2], len(x[0]), x[1]),
reverse=True, reverse=True,
) )
@ -753,7 +764,7 @@ class LicensePlateProcessor(RealTimeProcessorApi):
""" """
predictions = self.yolov9_detection_model(input) predictions = self.yolov9_detection_model(input)
confidence_threshold = self.lpr_config.threshold confidence_threshold = self.lpr_config.detection_threshold
top_score = -1 top_score = -1
top_box = None top_box = None
@ -968,6 +979,12 @@ class LicensePlateProcessor(RealTimeProcessorApi):
if not license_plate: if not license_plate:
return return
if license_plate.get("score") < self.lpr_config.detection_threshold:
logger.debug(
f"Plate detection score is less than the threshold ({license_plate['score']:0.2f} < {self.lpr_config.detection_threshold})"
)
return
license_plate_box = license_plate.get("box") license_plate_box = license_plate.get("box")
# check that license plate is valid # check that license plate is valid
@ -1043,7 +1060,7 @@ class LicensePlateProcessor(RealTimeProcessorApi):
return return
# Check against minimum confidence threshold # Check against minimum confidence threshold
if avg_confidence < self.lpr_config.threshold: if avg_confidence < self.lpr_config.recognition_threshold:
logger.debug( logger.debug(
f"Average confidence {avg_confidence} is less than threshold ({self.lpr_config.threshold})" f"Average confidence {avg_confidence} is less than threshold ({self.lpr_config.threshold})"
) )