re-crop to the object rather than the region

This commit is contained in:
Blake Blackshear 2020-12-19 08:48:34 -06:00
parent 899d41f361
commit af8594c5c6
2 changed files with 8 additions and 5 deletions

View File

@ -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])))

View File

@ -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 {}