From 45f7db5cf1ff412ddf749b6aaee3e3f0308ba8b8 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 1 Sep 2023 06:03:47 -0600 Subject: [PATCH] Show sub label in debug view when available (#7567) * Show sub label in debug view if available * Ensure sub label is printable to be used --- frigate/object_processing.py | 11 ++++++++++- frigate/util/image.py | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frigate/object_processing.py b/frigate/object_processing.py index 83684e1b6..a4bfb3fd9 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -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,13 +510,21 @@ class CameraState: # draw the bounding boxes on the frame box = obj["box"] + 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], box[1], box[2], box[3], - obj["label"], + text, f"{obj['score']:.0%} {int(obj['area'])}", thickness=thickness, color=color, diff --git a/frigate/util/image.py b/frigate/util/image.py index 4af94500d..d5eaaf885 100644 --- a/frigate/util/image.py +++ b/frigate/util/image.py @@ -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)