placeholder for non frigate+ model lp detection

This commit is contained in:
Josh Hawkins 2024-10-26 07:15:55 -05:00
parent e1c541735a
commit 19b688a55d

View File

@ -75,6 +75,9 @@ class EmbeddingMaintainer(threading.Thread):
# set license plate recognition conditions # set license plate recognition conditions
self.lpr_config = self.config.lpr self.lpr_config = self.config.lpr
self.requires_license_plate_detection = (
"license_plate" not in self.config.model.all_attributes
)
self.detected_license_plates: dict[str, dict[str, any]] = {} self.detected_license_plates: dict[str, dict[str, any]] = {}
if self.lpr_config.enabled: if self.lpr_config.enabled:
@ -485,6 +488,11 @@ class EmbeddingMaintainer(threading.Thread):
if resp.status_code == 200: if resp.status_code == 200:
self.detected_faces[id] = avg_score self.detected_faces[id] = avg_score
def _detect_license_plate(self, input: np.ndarray) -> tuple[int, int, int, int]:
"""Return the dimensions of the input image as [x, y, width, height]."""
height, width = input.shape[:2]
return (0, 0, width, height)
def _process_license_plate( def _process_license_plate(
self, obj_data: dict[str, any], frame: np.ndarray self, obj_data: dict[str, any], frame: np.ndarray
) -> None: ) -> None:
@ -511,6 +519,27 @@ class EmbeddingMaintainer(threading.Thread):
license_plate: Optional[dict[str, any]] = None license_plate: Optional[dict[str, any]] = None
if self.requires_license_plate_detection:
logger.debug("Running manual license_plate detection.")
car_box = obj_data.get("box")
if not car_box:
return None
rgb = cv2.cvtColor(frame, cv2.COLOR_YUV2RGB_I420)
left, top, right, bottom = car_box
car = rgb[top:bottom, left:right]
license_plate = self._detect_license_plate(car)
if not license_plate:
logger.debug("Detected no license plates for car object.")
return
license_plate_frame = car[
license_plate[1] : license_plate[3], license_plate[0] : license_plate[2]
]
license_plate_frame = cv2.cvtColor(license_plate_frame, cv2.COLOR_RGB2BGR)
else:
# don't run for object without attributes # don't run for object without attributes
if not obj_data.get("current_attributes"): if not obj_data.get("current_attributes"):
logger.debug("No attributes to parse.") logger.debug("No attributes to parse.")
@ -533,7 +562,10 @@ class EmbeddingMaintainer(threading.Thread):
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
if not license_plate_box or area(license_plate_box) < self.config.lpr.min_area: if (
not license_plate_box
or area(license_plate_box) < self.config.lpr.min_area
):
logger.debug(f"Invalid license plate box {license_plate}") logger.debug(f"Invalid license plate box {license_plate}")
return return