From 3bb3aecf974efff05c86715a55755a4027ae45f0 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 12 Mar 2022 08:56:28 -0500 Subject: [PATCH] Address review comments - Accept `ratio` default - Rename `bounds` to `box` for consistency - Add migration for new field Issue: #2948 --- frigate/config.py | 2 +- frigate/video.py | 18 +++++------ migrations/007_add_object_filter_ratio.py | 38 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 migrations/007_add_object_filter_ratio.py diff --git a/frigate/config.py b/frigate/config.py index 7be00c888..026e93c73 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -215,7 +215,7 @@ class FilterConfig(FrigateBaseModel): title="Minimum ratio of bounding box's width/height for object to be counted.", ) max_ratio: float = Field( - default=24000000, # @todo: Is there a way to make this `math.inf` but still load from YAML? + default=24000000, title="Maximum ratio of bounding box's width/height for object to be counted.", ) threshold: float = Field( diff --git a/frigate/video.py b/frigate/video.py index 32c212988..80eef7551 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -39,7 +39,7 @@ logger = logging.getLogger(__name__) def filtered(obj, objects_to_track, object_filters): object_name = obj[0] object_score = obj[1] - object_bounds = obj[2] + object_box = obj[2] object_area = obj[3] if not object_name in objects_to_track: @@ -65,9 +65,9 @@ def filtered(obj, objects_to_track, object_filters): if not obj_settings.mask is None: # compute the coordinates of the object and make sure # the location isn't outside the bounds of the image (can happen from rounding) - object_xmin = object_bounds[0] - object_xmax = object_bounds[2] - object_ymax = object_bounds[3] + object_xmin = object_box[0] + object_xmax = object_box[2] + object_ymax = object_box[3] y_location = min(int(object_ymax), len(obj_settings.mask) - 1) x_location = min( int((object_xmax + object_xmin) / 2.0), @@ -626,13 +626,13 @@ def process_frames( for group in detected_object_groups.values(): # apply non-maxima suppression to suppress weak, overlapping bounding boxes - bounds = o[2] # xmin, ymin, xmax, ymax + box = o[2] # xmin, ymin, xmax, ymax boxes = [ ( - bounds[0], - bounds[1], - bounds[2] - bounds[0], - bounds[3] - bounds[1], + box[0], + box[1], + box[2] - box[0], + box[3] - box[1], ) for o in group ] diff --git a/migrations/007_add_object_filter_ratio.py b/migrations/007_add_object_filter_ratio.py new file mode 100644 index 000000000..ebd6da8b1 --- /dev/null +++ b/migrations/007_add_object_filter_ratio.py @@ -0,0 +1,38 @@ +"""Peewee migrations -- 007_add_object_filter_ratio.py. + +Some examples (model - class or model name):: + + > Model = migrator.orm['model_name'] # Return model in current state by name + + > migrator.sql(sql) # Run custom SQL + > migrator.python(func, *args, **kwargs) # Run python code + > migrator.create_model(Model) # Create a model (could be used as decorator) + > migrator.remove_model(model, cascade=True) # Remove a model + > migrator.add_fields(model, **fields) # Add fields to a model + > migrator.change_fields(model, **fields) # Change fields + > migrator.remove_fields(model, *field_names, cascade=True) + > migrator.rename_field(model, old_field_name, new_field_name) + > migrator.rename_table(model, new_table_name) + > migrator.add_index(model, *col_names, unique=False) + > migrator.drop_index(model, *col_names) + > migrator.add_not_null(model, *field_names) + > migrator.drop_not_null(model, *field_names) + > migrator.add_default(model, field_name, default) + +""" + +import peewee as pw +from frigate.models import Event + +SQL = pw.SQL + + +def migrate(migrator, database, fake=False, **kwargs): + migrator.add_fields( + Event, + ratio=pw.FloatField(), + ) + + +def rollback(migrator, database, fake=False, **kwargs): + migrator.remove_fields(Event, ["ratio"])