roflcoopter / viseron

Self-hosted, local only NVR and AI Computer Vision software. With features such as object detection, motion detection, face recognition and more, it gives you the power to keep an eye on your home, office or any other place you want to monitor.
MIT License
1.76k stars 179 forks source link

Mask Coordinates for Darknet not working as expected #544

Closed tokenwizard closed 1 year ago

tokenwizard commented 1 year ago

I'm trying to follow along the documentation, and I think this is what I'm supposed to plug in for the mask coordinates.

The Documentation does not show the mask/coordinates pieces within the overall config file, so I'm not sure if my placement is appropriate, but the Configuration page does not show any errors.

I used the image-map.net link and drew a rectangle bounding box that spit out these coordinates and then plugged them into the config.

image

When I restart, I am getting an error related to these values and Darknet fails to load:

image

roflcoopter commented 1 year ago

Yeah this could be a bit more clear in the docs.

You need to use the "poly" option when creating the mask, not the "rect" option. Viseron needs at least 3 mask points.

Will make sure to describe this better.

tokenwizard commented 1 year ago

I've updated my mask coordinates like so: image

But I'm still getting this error at startup: image

roflcoopter commented 1 year ago

the value of mask has to be a list, like so:

darknet:
  object_detector:
    cameras:
      camera_1:
        ...
        mask:
          - coordinates:
              - x: 400
                y: 200
              - x: 1000
                y: 200
              - x: 1000
                y: 750
              - x: 400
                y: 750

If you paste your config between triple backticks (```) i can help you fix the format. Will add an example config to the docs as well for clarity.

tokenwizard commented 1 year ago

Here is the detector-related settings. The "streetleft" is the camera that has the mask.

darknet:
  object_detector:
    cameras:
      1_driveway:  # Attach detector to the configured camera_1 above
        fps: 1
        scan_on_motion_only: true  # Scan for objects even when there is no motion
        labels:
          - label: person
            confidence: 0.70
            trigger_recorder: true
          - label: cat
            confidence: 0.70
            trigger_recorder: true

      2_frontleft:  # Attach detector to the configured camera_2 above
        fps: 1
        scan_on_motion_only: true
        labels:
          - label: person
            confidence: 0.75
            trigger_recorder: true
          - label: cat
            confidence: 0.70
            trigger_recorder: true        

      3_frontright:  # Attach detector to the configured camera_2 above
        fps: 1
        scan_on_motion_only: true
        labels:
          - label: person
            confidence: 0.75
            trigger_recorder: true
          - label: cat
            confidence: 0.70
            trigger_recorder: true     

      4_streetleft:  # Attach detector to the configured camera_2 above
        fps: 1
        scan_on_motion_only: true
        labels:
          - label: person
            confidence: 0.75
            trigger_recorder: true
          - label: cat
            confidence: 0.70
            trigger_recorder: true 
        mask: 
          coordinates:
            - x: 1911
              y: 734
            - x: 1727
              y: 795
            - x: 1660
              y: 1056
            - x: 1904
              y: 1063

      5_streetright:  # Attach detector to the configured camera_2 above
        fps: 1
        scan_on_motion_only: true
        labels:
          - label: person
            confidence: 0.75
            trigger_recorder: true
          - label: cat
            confidence: 0.70
            trigger_recorder: true 

      6_porch:  # Attach detector to the configured camera_1 above
        fps: 1
        scan_on_motion_only: true  # Scan for objects even when there is no motion
        labels:
          - label: person
            confidence: 0.70
            trigger_recorder: true
          - label: cat
            confidence: 0.70
            trigger_recorder: true
gofaster commented 1 year ago

I think there needs to be a dash in front of coordinates to indicate a list .

        mask: 
          - coordinates:
            - x: 1911
              y: 734
            - x: 1727
              y: 795
            - x: 1660
              y: 1056
            - x: 1904
              y: 1063
tokenwizard commented 1 year ago

I think there needs to be a dash in front of coordinates to indicate a list .

        mask: 
          - coordinates:
            - x: 1911
              y: 734
            - x: 1727
              y: 795
            - x: 1660
              y: 1056
            - x: 1904
              y: 1063

That was it! I missed that additional dash before the "coordinates" parameter. It is starting up now without giving that error related to the coordinates. Now I just have the other error shown here (being investigated in another issue).

image

tokenwizard commented 1 year ago

So the coordinates format is resolved now and the Darknet detector is initializing. However the Mask does not seem to be working properly.

I'm getting a false detection in the bottom-right corner: image

Here is the Mask I created to get the coordinates: image

Also, in my config, I have it set to only detect when Motion is detected, but this object being detected as a person is stationary. image

image

roflcoopter commented 1 year ago

The mask works by checking if the bottom center of the object is within the mask, an if so it is discarded. Judging by your image it looks like the bottom center is slightly below your mask. Try stretching the mask to the very bottom of the frame. I assume your resolution is 1920x1080, if thats the case then it should be enough to set your last two Y-coordinates to 1080.

scan_on_motion_only does not affect where objects are detected, it just makes Viseron scan for objects when there is motion

tokenwizard commented 1 year ago

Ok, I will try that.

If I'm understanding the scan_on_motion_only settings, wouldn't that mean that no object detection should occur unless motion is detected, triggering the object detection? My expectation of this would be that no stationary objects would ever be detected.

Or am I just misunderstanding that?

roflcoopter commented 1 year ago

You are correct!

My guess is that something triggered the motion (wind, sun etc) or your settings are too sensitive. They can be tweaked to make sure it works as good as possible for your particular scene

tokenwizard commented 1 year ago

Ok, so it scans the whole scene for an object, not just the area where motion is detected? I guess that makes sense. I will play with the settings a bit to see if I can get them where I need them.

roflcoopter commented 1 year ago

Yes it scans everything. Only scanning in areas where there is motion is technically possible but it would add a lot of complexity i am afraid

tokenwizard commented 1 year ago

Ok, we can close this out. The issue I was reporting was a non-issue. Just need a bit of clarification int he documentation on what the mask/coordinates section of the config should look like. I was missing a "-" before the "coordinates" tag.