From 24bfe9f3e8b3d2cf741e1c7e4bfddee48de15014 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sat, 19 Dec 2020 08:48:34 -0600 Subject: [PATCH] re-crop to the object rather than the region --- frigate/http.py | 4 +++- frigate/object_processing.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index f3102cde0..4a25b59f6 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -13,6 +13,7 @@ from peewee import SqliteDatabase, operator, fn, DoesNotExist from playhouse.shortcuts import model_to_dict from frigate.models import Event +from frigate.util import calculate_region from frigate.version import VERSION logger = logging.getLogger(__name__) @@ -190,7 +191,8 @@ def best(camera_name, label): crop = bool(request.args.get('crop', 0, type=int)) if crop: - region = best_object.get('region', [0,0,300,300]) + box = best_object.get('box', (0,0,300,300)) + region = calculate_region(best_frame.shape, box[0], box[1], box[2], box[3], 1.1) best_frame = best_frame[region[1]:region[3], region[0]:region[2]] height = int(request.args.get('h', str(best_frame.shape[0]))) diff --git a/frigate/object_processing.py b/frigate/object_processing.py index 0ef30d7cd..3fe66e93a 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -20,7 +20,7 @@ import numpy as np from frigate.config import FrigateConfig, CameraConfig from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR from frigate.edgetpu import load_labels -from frigate.util import SharedMemoryFrameManager, draw_box_with_label +from frigate.util import SharedMemoryFrameManager, draw_box_with_label, calculate_region logger = logging.getLogger(__name__) @@ -187,7 +187,8 @@ class TrackedObject(): f"{int(self.thumbnail_data['score']*100)}% {int(self.thumbnail_data['area'])}", thickness=thickness, color=color) if snapshot_config.crop_to_region: - region = self.thumbnail_data['region'] + box = self.thumbnail_data['box'] + region = calculate_region(best_frame.shape, box[0], box[1], box[2], box[3], 1.1) best_frame = best_frame[region[1]:region[3], region[0]:region[2]] if snapshot_config.height: @@ -460,8 +461,8 @@ class TrackedObjectProcessor(threading.Thread): camera_state = self.camera_states[camera] if label in camera_state.best_objects: best_obj = camera_state.best_objects[label] - best = best_obj.to_dict() - best['frame'] = camera_state.frame_cache[best_obj.thumbnail_data['frame_time']] + best = best_obj.thumbnail_data.copy() + best['frame'] = camera_state.frame_cache.get(best_obj.thumbnail_data['frame_time']) return best else: return {}