소스 검색

add ability to draw bounding boxes/timestamps on snapshots

Blake Blackshear 4 년 전
부모
커밋
bf93fbb357
2개의 변경된 파일13개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      detect_objects.py
  2. 11 0
      frigate/object_processing.py

+ 2 - 1
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', {})
 

+ 11 - 0
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()