blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
18.2k stars 1.66k forks source link

[Support/Bug]: Zones and Masks being ignored #3392

Closed droans closed 2 years ago

droans commented 2 years ago

Describe the problem you are having

I created some zones and masks for my cameras so Frigate will ignore them. While they appear to be working on the front end (no events are created), they don't actually seem to be doing anything. The "Events" option for each event type still shows events from discarded areas even though they do not appear in the event log. The Home Assistant integration still captures these events and records them as motion.

Some examples:

Camera:

image

With zones and object masks:

image

Person events:

image

Person Motion Camera from Home Assistant:

camera

Version

0.10.1-83481AF

Frigate config file

{
  "birdseye": {
    "enabled": true,
    "height": 720,
    "mode": "objects",
    "quality": 8,
    "width": 1280
  },
  "cameras": {
    "front_yard": {
      "best_image_timeout": 60,
      "detect": {
        "enabled": true,
        "fps": 5,
        "height": 480,
        "max_disappeared": 25,
        "stationary": {
          "interval": 30,
          "max_frames": {
            "default": null,
            "objects": {}
          },
          "threshold": 10
        },
        "width": 704
      },
      "ffmpeg": {
        "global_args": [
          "-hide_banner",
          "-loglevel",
          "warning"
        ],
        "hwaccel_args": [],
        "input_args": "-c:v h264_cuvid -fflags +genpts+discardcorrupt",
        "inputs": [
          {
            "global_args": [],
            "hwaccel_args": [],
            "input_args": [],
            "path": "rtsp://XXXX:XXXX@10.10.20.51:554/cam/realmonitor?channel=1&subtype=0&authbasic=64",
            "roles": [
              "record"
            ]
          },
          {
            "global_args": [],
            "hwaccel_args": [],
            "input_args": [],
            "path": "rtsp://XXXX:XXXX@10.10.20.51:554/cam/realmonitor?channel=1&subtype=0&authbasic=64",
            "roles": [
              "detect",
              "rtmp"
            ]
          }
        ],
        "output_args": {
          "detect": [
            "-f",
            "rawvideo",
            "-pix_fmt",
            "yuv420p"
          ],
          "record": [
            "-f",
            "segment",
            "-segment_time",
            "10",
            "-segment_format",
            "mp4",
            "-reset_timestamps",
            "1",
            "-strftime",
            "1",
            "-c",
            "copy",
            "-an"
          ],
          "rtmp": [
            "-c",
            "copy",
            "-f",
            "flv"
          ]
        }
      },
      "ffmpeg_cmds": [
        {
          "cmd": "ffmpeg -hide_banner -loglevel warning -c:v h264_cuvid -fflags +genpts+discardcorrupt -i rtsp://XXXX:XXXX@10.10.20.51:554/cam/realmonitor?channel=1&subtype=0&authbasic=64 -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c copy -an /tmp/cache/front_yard-%Y%m%d%H%M%S.mp4",
          "roles": [
            "record"
          ]
        },
        {
          "cmd": "ffmpeg -hide_banner -loglevel warning -c:v h264_cuvid -fflags +genpts+discardcorrupt -i rtsp://XXXXXX:XXXXXX@10.10.20.51:554/cam/realmonitor?channel=1&subtype=0&authbasic=64 -c copy -f flv rtmp://127.0.0.1/live/front_yard -r 5 -s 704x480 -f rawvideo -pix_fmt yuv420p pipe:",
          "roles": [
            "detect",
            "rtmp"
          ]
        }
      ],
      "live": {
        "height": 720,
        "quality": 8
      },
      "motion": {
        "contour_area": 30,
        "delta_alpha": 0.2,
        "frame_alpha": 0.2,
        "frame_height": 50,
        "improve_contrast": false,
        "mask": [
          "362,478,408,443,468,472,517,442,537,419,576,386,600,341,665,218,691,113,687,22,583,18,465,31,381,49,268,85,0,193,1,0,704,0,704,58,704,480"
        ],
        "threshold": 25
      },
      "mqtt": {
        "bounding_box": true,
        "crop": true,
        "enabled": true,
        "height": 270,
        "quality": 70,
        "required_zones": [],
        "timestamp": true
      },
      "name": "front_yard",
      "objects": {
        "filters": {
          "bicycle": {
            "mask": null,
            "max_area": 24000000,
            "min_area": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "bus": {
            "mask": null,
            "max_area": 24000000,
            "min_area": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "car": {
            "mask": null,
            "max_area": 24000000,
            "min_area": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "dog": {
            "mask": null,
            "max_area": 24000000,
            "min_area": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "motorcycle": {
            "mask": null,
            "max_area": 24000000,
            "min_area": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "person": {
            "mask": null,
            "max_area": 24000000,
            "min_area": 0,
            "min_score": 0.5,
            "threshold": 0.7
          }
        },
        "mask": "",
        "track": [
          "person",
          "bicycle",
          "car",
          "motorcycle",
          "bus",
          "dog"
        ]
      },
      "record": {
        "enabled": true,
        "events": {
          "max_seconds": 300,
          "objects": null,
          "post_capture": 5,
          "pre_capture": 5,
          "required_zones": [
            "driveway",
            "sidewalk_to_door",
            "frontyard",
            "sideyard"
          ],
          "retain": {
            "default": 10,
            "mode": "motion",
            "objects": {}
          }
        },
        "expire_interval": 60,
        "retain": {
          "days": 10,
          "mode": "all"
        },
        "retain_days": null
      },
      "rtmp": {
        "enabled": true
      },
      "snapshots": {
        "bounding_box": true,
        "clean_copy": true,
        "crop": false,
        "enabled": true,
        "height": null,
        "quality": 70,
        "required_zones": [
          "driveway",
          "sidewalk_to_door",
          "frontyard",
          "sideyard"
        ],
        "retain": {
          "default": 10,
          "mode": "motion",
          "objects": {
            "car": 15,
            "dog": 15,
            "person": 15
          }
        },
        "timestamp": true
      },
      "timestamp_style": {
        "color": {
          "blue": 255,
          "green": 255,
          "red": 255
        },
        "effect": null,
        "format": "%m/%d/%Y %H:%M:%S",
        "position": "tl",
        "thickness": 2
      },
      "zones": {
        "driveway": {
          "coordinates": "74,163,111,203,134,232,220,331,301,395,387,457,416,437,471,480,566,398,602,344,642,263,670,197,524,140,408,106,283,82",
          "filters": {},
          "objects": []
        },
        "frontyard": {
          "coordinates": "288,81,454,44,551,31,636,48,704,69,677,141,602,112,555,149",
          "filters": {},
          "objects": []
        },
        "sidewalk_to_door": {
          "coordinates": "555,151,616,107,673,126,618,176",
          "filters": {},
          "objects": []
        },
        "sideyard": {
          "coordinates": "0,480,362,480,400,449,342,430,247,360,147,253,89,176,0,218",
          "filters": {},
          "objects": []
        }
      }
    },
  "database": {
    "path": "/media/frigate/frigate.db"
  },
  "detect": {
    "enabled": true,
    "fps": 5,
    "height": 720,
    "max_disappeared": null,
    "stationary": {
      "interval": 30,
      "max_frames": {
        "default": null,
        "objects": {}
      },
      "threshold": 10
    },
    "width": 1280
  },
  "detectors": {
    "cpu": {
      "device": "usb",
      "num_threads": 3,
      "type": "cpu"
    }
  },
  "environment_vars": {},
  "ffmpeg": {
    "global_args": [
      "-hide_banner",
      "-loglevel",
      "warning"
    ],
    "hwaccel_args": [],
    "input_args": [
      "-avoid_negative_ts",
      "make_zero",
      "-fflags",
      "+genpts+discardcorrupt",
      "-rtsp_transport",
      "tcp",
      "-stimeout",
      "5000000",
      "-use_wallclock_as_timestamps",
      "1"
    ],
    "output_args": {
      "detect": [
        "-f",
        "rawvideo",
        "-pix_fmt",
        "yuv420p"
      ],
      "record": [
        "-f",
        "segment",
        "-segment_time",
        "10",
        "-segment_format",
        "mp4",
        "-reset_timestamps",
        "1",
        "-strftime",
        "1",
        "-c",
        "copy",
        "-an"
      ],
      "rtmp": [
        "-c",
        "copy",
        "-f",
        "flv"
      ]
    }
  },
  "live": {
    "height": 720,
    "quality": 8
  },
  "logger": {
    "default": "info",
    "logs": {}
  },
  "model": {
    "height": 320,
    "labelmap": {},
    "labelmap_path": null,
    "path": null,
    "width": 320
  },
  "motion": null,
  "mqtt": {
    "client_id": "frigate",
    "host": "192.168.86.36",
    "password": null,
    "port": 1883,
    "stats_interval": 60,
    "tls_ca_certs": null,
    "tls_client_cert": null,
    "tls_client_key": null,
    "tls_insecure": null,
    "topic_prefix": "frigate",
    "user": null
  },
  "objects": {
    "filters": null,
    "mask": "",
    "track": [
      "person"
    ]
  },
  "record": {
    "enabled": true,
    "events": {
      "max_seconds": 300,
      "objects": null,
      "post_capture": 5,
      "pre_capture": 5,
      "required_zones": [],
      "retain": {
        "default": 10,
        "mode": "motion",
        "objects": {}
      }
    },
    "expire_interval": 60,
    "retain": {
      "days": 10,
      "mode": "all"
    },
    "retain_days": null
  },
  "rtmp": {
    "enabled": true
  },
  "snapshots": {
    "bounding_box": true,
    "clean_copy": true,
    "crop": false,
    "enabled": true,
    "height": null,
    "quality": 70,
    "required_zones": [],
    "retain": {
      "default": 10,
      "mode": "motion",
      "objects": {
        "car": 15,
        "dog": 15,
        "person": 15
      }
    },
    "timestamp": true
  },
  "timestamp_style": {
    "color": {
      "blue": 255,
      "green": 255,
      "red": 255
    },
    "effect": null,
    "format": "%m/%d/%Y %H:%M:%S",
    "position": "tl",
    "thickness": 2
  }
}

Relevant log output

N/A

FFprobe output from your camera

N/A

Frigate stats

{"back_yard":{"camera_fps":5.1,"capture_pid":262,"detection_fps":0.0,"pid":254,"process_fps":5.1,"skipped_fps":0.0},"detection_fps":0.0,"detectors":{"cpu":{"detection_start":0.0,"inference_s
peed":28.26,"pid":233}},"east_side_yard":{"camera_fps":5.0,"capture_pid":275,"detection_fps":0.0,"pid":256,"process_fps":5.0,"skipped_fps":0.0},"front_yard":{"camera_fps":5.1,"capture_pid":2
59,"detection_fps":0.0,"pid":253,"process_fps":5.1,"skipped_fps":0.0},"living_room":{"camera_fps":5.1,"capture_pid":257,"detection_fps":0.0,"pid":252,"process_fps":5.1,"skipped_fps":0.0},"se
rvice":{"storage":{"/dev/shm":{"free":532.1,"mount_type":"tmpfs","total":536.9,"used":4.8},"/media/frigate/clips":{"free":8364700.3,"mount_type":"xfs","total":13998380.5,"used":5633680.2},"/
media/frigate/recordings":{"free":8364700.3,"mount_type":"xfs","total":13998380.5,"used":5633680.2},"/tmp/cache":{"free":5977.3,"mount_type":"tmpfs","total":6000.0,"used":22.7}},"temperature
s":{},"uptime":311036,"version":"0.10.1-83481af"},"west_side_yard":{"camera_fps":5.1,"capture_pid":267,"detection_fps":0.0,"pid":255,"process_fps":5.1,"skipped_fps":0.0}}

Operating system

Other Linux

Install method

Docker Compose

Coral version

CPU (no coral)

Network connection

Wired

Camera make and model

Amcrest

Any other information that may be helpful

No response

NickM-27 commented 2 years ago

So there's a few things to understand here:

  1. It is highly discouraged to add motions masks to large areas / to block off objects, frigate is not designed to work this way. See this section of the docs for an explainer. It may cause adverse behavior.
  2. It's not clear what you mean by The Home Assistant integration still captures these events and records them as motion. but I think you are saying that the camera.whatever_person still updates. This is expected as all detections will be sent over MQTT regardless of the event being added to the list or not. You can set mqtt -> required_zones to not send snapshots over MQTT unless the object is in the specified zones.
droans commented 2 years ago

The settings change doesn't seem to be making a difference:

image

image

No masks exist anymore. MQTT settings for the camera have required_zones set to be any of those boxed areas, but the motion is still outside of them.

The difference now is that, without the masks, they are getting recognized in the Frigate events and it says the motion came from the blue colored zone. I'm wondering if this is due to the re-bounding of the boxes. Motion is detected due to the leaves, but isn't recognized so it keeps resizing the bound box until it gets the car despite the car being outside of the motion boxes.

It's also not just the camera, but the binary sensors created for the detection. However, I assume they're correlated and always update together.

NickM-27 commented 2 years ago

The settings change doesn't seem to be making a difference:

If the events are actually being registered then it would make sense that the MQTT snapshots are still sent.

The difference now is that, without the masks, they are getting recognized in the Frigate events and it says the motion came from the blue colored zone.

To be clear zones presence is ONLY true when the bottom center of the objects bounding box is inside the zone. Motion box position won't affect zone presence at all.

I'm wondering if this is due to the re-bounding of the boxes. Motion is detected due to the leaves, but isn't recognized so it keeps resizing the bound box until it gets the car despite the car being outside of the motion boxes.

That's not how it works. For the car to be apart of that zone the bottom center of its bounding box needed to be inside the zone for at least 1 frame.

It's also not just the camera, but the binary sensors created for the detection. However, I assume they're correlated and always update together.

Yes that's correct they are directly related to each other.

Seeing as the blue zone is the front yard I don't think a car needs to be in the list of items for that zone which may help. Main thing to keep in mind here is that object presence is based on the bottom center of the objects bounding box which only needs to be inside the zone for 1 frame to be considered in the zone. Also, the snapshot won't necessarily be of this frame.

As far as the MQTT goes, I need to look into what it does exactly, but more clarification on what you're trying to accomplish / what's happening on the HA side will make it easier to make a recommendation

droans commented 2 years ago

From watching it live, it appears the issue is the motion boxes.

When the wind blows, the shadows from the trees cause enough motion that Frigate generates a motion box covering a large portion of the feed. Eventually, it settles on something that was outside of the zone the whole time.

As an example, here's a mailbox that Frigate believed was the source earlier when the trees blew and triggered motion in my driveway. The mailbox was subsequently detected for about 18 minutes before it stopped.

snapshot-1656601087 931645-d27qj9

Unfortunately, the shadow of the trees cover a large portion of my driveway and yard every morning and night. I can't just mask them out.

For now, I have increased the minimum area for vehicles and people to 2240 and 3000 respectively since that should be the bare minimum size in areas I care about.

NickM-27 commented 2 years ago

Yes, lots of motion makes it more likely for an errant detection that can be a total false positive or a true positive but including more than just the object in the bounding box.

min_area is a good approach and should help a lot

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.