From bf93fbb3574e92dc4e678f75f4c557a6755f90e6 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Fri, 16 Oct 2020 16:11:08 -0500 Subject: [PATCH] add ability to draw bounding boxes/timestamps on snapshots --- detect_objects.py | 3 ++- frigate/object_processing.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/detect_objects.py b/detect_objects.py index 47f5ae444..d8813123f 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -164,7 +164,8 @@ def main(): for name, config in CONFIG['cameras'].items(): config['snapshots'] = { 'show_timestamp': config.get('snapshots', {}).get('show_timestamp', True), - 'draw_zones': config.get('snapshots', {}).get('draw_zones', False) + 'draw_zones': config.get('snapshots', {}).get('draw_zones', False), + 'draw_bounding_boxes': config.get('snapshots', {}).get('draw_bounding_boxes', True) } config['zones'] = config.get('zones', {}) diff --git a/frigate/object_processing.py b/frigate/object_processing.py index 4b2f2f8d8..e473e572c 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -269,6 +269,12 @@ class TrackedObjectProcessor(threading.Thread): if not 'frame' in obj: return best_frame = cv2.cvtColor(obj['frame'], cv2.COLOR_YUV2BGR_I420) + if self.camera_config[camera]['snapshots']['draw_bounding_boxes']: + thickness = 2 + color = COLOR_MAP[obj['label']] + box = obj['box'] + draw_box_with_label(best_frame, box[0], box[1], box[2], box[3], obj['label'], f"{int(obj['score']*100)}% {int(obj['area'])}", thickness=thickness, color=color) + mqtt_config = self.camera_config[camera].get('mqtt', {'crop_to_region': False}) if mqtt_config.get('crop_to_region'): region = obj['region'] @@ -277,6 +283,11 @@ class TrackedObjectProcessor(threading.Thread): height = int(mqtt_config['snapshot_height']) width = int(height*best_frame.shape[1]/best_frame.shape[0]) best_frame = cv2.resize(best_frame, dsize=(width, height), interpolation=cv2.INTER_AREA) + + if self.camera_config[camera]['snapshots']['show_timestamp']: + time_to_show = datetime.datetime.fromtimestamp(obj['frame_time']).strftime("%m/%d/%Y %H:%M:%S") + cv2.putText(best_frame, time_to_show, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, fontScale=.8, color=(255, 255, 255), thickness=2) + ret, jpg = cv2.imencode('.jpg', best_frame) if ret: jpg_bytes = jpg.tobytes()