neilenns / node-deepstackai-trigger

Detects motion using Deepstack AI and calls registered triggers based on trigger rules.
MIT License
165 stars 28 forks source link

Reverse/Inverse masks #384

Closed NewToTown closed 3 years ago

NewToTown commented 3 years ago

First of all thank you for all your work on this project, it is amazing.

Is your feature request related to a problem? Please describe. Setup entails a camera aimed down the driveway with a view of the street (which runs horizontal across the frame) with neighbors houses across the street. When masking out the neighbors driveways (due to parked cars) when a vehicle drives down the street (due to the angle and distance of the camera) the vehicle's detection box (especially if it is a van/truck) often extends inside the masked area of the neighbors driveway.

Describe the solution you'd like A reverse/inverse mask that will cause a trigger only if part of the detected object is within the reverse masked region. The street could be marked with the reverse mask which would then only cause alerts to trigger when a vehicle is detected in the street. This would also eliminate the need to create multiple masked zones for each neighbors driveway.

Describe alternatives you've considered Decreased the time (from 5 seconds to 1 second) between JPG snapshots created by Blue Iris to increase the chance that the vehicle driving down the street will not hit on a masked area from a neighbors driveway. This lead to an decrease in performance as 5x more JPGs are now being processed.

neilenns commented 3 years ago

Hmm, interesting. So basically instead of a "if anything is inside this mask skip the trigger" mask you want an "if anything is inside this mask fire the trigger" mask?

NewToTown commented 3 years ago

Hmm, interesting. So basically instead of a "if anything is inside this mask skip the trigger" mask you want an "if anything is inside this mask fire the trigger" mask?

Yes, that sums it up quite concisely.

neilenns commented 3 years ago

This turned out to be surprisingly easy. There's now an activateRegions property on triggers that takes an array of mask objects. If the detected object overlaps one of those regions then the trigger will fire. If it doesn't then it won't. In theory you can combine both masks and activate regions as well. In that case the detected object must be outside of all masked areas and inside at least one of the activate areas.

Please try this out and see if it works for you. Change your docker-compose.yaml to point to the issue384 tagged image instead of latest.

neilenns commented 3 years ago

@NewToTown Have you had a chance to try this build out and see if it works for your situation?

NewToTown commented 3 years ago

@NewToTown Have you had a chance to try this build out and see if it works for your situation?

Sorry I wasn't able to test during the day until now. It works great with just the activateRegions in the triggers.json file. If the file has both masks and activateRegions then the masks takes priority and stops the trigger from firing.

neilenns commented 3 years ago

Yes, that's how it's implemented:

In that case the detected object must be outside of all masked areas and inside at least one of the activate areas.

I'm not sure how else it could work without being confusing. I expect in most (all?) cases people will use one or the other, not both.

NewToTown commented 3 years ago

Yes, that's how it's implemented:

In that case the detected object must be outside of all masked areas and inside at least one of the activate areas.

I'm not sure how else it could work without being confusing. I expect in most (all?) cases people will use one or the other, not both.

I agree, thinking about it more not sure what scenario would prompt the need for both. Do you foresee the activateRegions eventually being implemented in the main trunk?

neilenns commented 3 years ago

Yes, I'll be merging and releasing it this weekend. Was just waiting for feedback from you that it was working as expected.