Ensure sub label is printable to be used

This commit is contained in:
Nick Mowen 2023-08-24 10:24:46 -06:00
parent 27052ec8bf
commit 04542c7857
2 changed files with 15 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from frigate.util.image import (
calculate_region,
draw_box_with_label,
draw_timestamp,
is_label_printable,
)
logger = logging.getLogger(__name__)
@ -509,7 +510,14 @@ class CameraState:
# draw the bounding boxes on the frame
box = obj["box"]
text = obj["label"] if not obj.get("sub_label") else obj["sub_label"][0]
text = (
obj["label"]
if (
not obj.get("sub_label")
or not is_label_printable(obj["sub_label"][0])
)
else obj["sub_label"][0]
)
draw_box_with_label(
frame_copy,
box[0],

View File

@ -4,6 +4,7 @@ import datetime
import logging
from abc import ABC, abstractmethod
from multiprocessing import shared_memory
from string import printable
from typing import AnyStr, Optional
import cv2
@ -154,6 +155,11 @@ def draw_box_with_label(
)
def is_label_printable(label) -> bool:
"""Check if label is printable."""
return not bool(set(label) - set(printable))
def calculate_region(frame_shape, xmin, ymin, xmax, ymax, model_size, multiplier=2):
# size is the longest edge and divisible by 4
size = int((max(xmax - xmin, ymax - ymin) * multiplier) // 4 * 4)