Repository: blakeblackshear/frigate

Issue:
Zone filters not working for overlapping areas
**Describe the bug**
If two zones (on the same camera) overlap, the zone filters are not respected and detected object is triggered in both zones.

**Version of frigate**
0.6.0-rc3

**Expected resuls**
If an object is detected in the overlapping area of configured zones, zone filters should be respected and report only for object matching specific zone filters.

**Config file**

```
objects:
  track:
    - person
  filters:
    person:
      min_area: 5000
      max_area: 1000000
      min_score: 0.5
      threshold: 0.5

  ipcam13:
    ffmpeg:
      input: rtsp://blabla
    #mask: ipcam13_stairs_mask.bmp
    zones:
      outside_yard:
        coordinates:
          - 0,0
          - 0,1078
          - 907,1078
          - 909,622
          - 1621,621
          - 1621,565
          - 1786,565
          - 1784,490
          - 1918,493
          - 1918,3
        filters:
          person:
            min_area: 5000
            max_area: 700000
            threshold: 0.75
      outside_stairs:
        coordinates:
          - 938,1078
          - 1918,1078
          - 1918,3
          - 1108,0
          - 1106,110
          - 940,112
        filters:
          person:
            min_area: 180000
            max_area: 700000
            threshold: 0.75
    fps: 4
    snapshots:
      show_timestamp: True
      draw_zones: True
    objects:
      track:
        - person
      filters:
        person:
          min_area: 5000
          max_area: 700000
          min_score: 0.5
          threshold: 0.75
```

In the above config, the outside_stairs zone is showing ON when a person is in the overlapping area even though they are smaller than the min_area filter.



Discussion:

Resolving patch:
diff --git a/detect_objects.py b/detect_objects.py
--- a/detect_objects.py
+++ b/detect_objects.py
@@ -267,13 +267,8 @@ def on_connect(client, userdata, flags, rc):
         camera_objects_config = config.get('objects', {})
         # get objects to track for camera
         objects_to_track = camera_objects_config.get('track', GLOBAL_OBJECT_CONFIG.get('track', ['person']))
-        # merge object filters
-        global_object_filters = GLOBAL_OBJECT_CONFIG.get('filters', {})
-        camera_object_filters = camera_objects_config.get('filters', {})
-        objects_with_config = set().union(global_object_filters.keys(), camera_object_filters.keys())
-        object_filters = {}
-        for obj in objects_with_config:
-            object_filters[obj] = {**global_object_filters.get(obj, {}), **camera_object_filters.get(obj, {})}
+        # get object filters
+        object_filters = camera_objects_config.get('filters', GLOBAL_OBJECT_CONFIG.get('filters', {}))
         config['objects'] = {
             'track': objects_to_track,
             'filters': object_filters
diff --git a/frigate/object_processing.py b/frigate/object_processing.py
--- a/frigate/object_processing.py
+++ b/frigate/object_processing.py
@@ -28,10 +28,9 @@
 
 def zone_filtered(obj, object_config):
     object_name = obj['label']
-    object_filters = object_config.get('filters', {})
 
-    if object_name in object_filters:
-        obj_settings = object_filters[object_name]
+    if object_name in object_config:
+        obj_settings = object_config[object_name]
 
         # if the min area is larger than the
         # detected object, don't add it to detected objects


Test patch: