-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple ROI boxes or non-square shape? #91
Comments
I have a couple of related issues on deepstack:
The challenge is to make it not too complicated to configure. If you can make any suggestions about what you want and how it could be configured that would be very helpful |
I did think about polygons etc to build a more complex zone, but as you suggested would make configuration complex and hard to setup/test/debug. If we allowed multiple ROI boxes, it becomes a bit of a pain do define complex/non-rectangular zones. If the focus is on simplicity, how about having the option to supply an exclusion mask... This would be a transparent PNG of the same dimensions as the source image. In this file we black out the areas to exclude, we then overlay this image on top of the source image before passing onto rekogntion. For the image your addon saves out with the boxes etc drawn on, it could still use the original source image, rather than the one that we actually sent to rekognition. This method would allow very complex zones to be applied easily. |
Can you provide a working example, either a PR or just some working python code? Your suggestion would provide simple config but then require users to use an extra tool to generate the mask. I am open to the idea of a Hassion addon which could be used for that. But then again an addon could also be used to generate the config even if it was just some complicated text |
I did try and do it against the actual codebase, but couldn't quite fathom it... Here's a basic example in isolation to show the concept working though...
|
How is the mask created? |
Transparent PNG file - Can use any image editor, gimp, photoshop, etc... I'm sure most people with the level of technical ability to be running home assistant with custom addons, and AWS keys etc will have no problem doing this? |
Probably true, but I want to roll this back into HA at some point and simplify as much as possible. One issue with using a mask before processing is that any object that is on the border risks being not detected since it will be cropped. Any comment on this? My current approach runs detection on the full frame, then uses the center of the object to decide if it's inside the ROI OR NOT |
Ah, that is a good point - I might have a look at how we can specify polygon coordinates then |
Building a polygon and then using shapely to test for presence of a point with the polygon is fairly effortless... Here I build a simple 4 point polygon for my ROI (Try using my camera image above as camera.jpg), I've also added two test points, one inside and one outside. We're loading a list of coordinates from YAML, then converting them to a list of tuples...
and then, this loads from a yaml file like so...
|
@geftactics I like this suggestion, will do. |
@geftactics do you know of any other integrations (preferably official) that are using config which involves an array? |
I think many do, but just not in YAML formatted this way... Not sure if it helps, but my code above will also work with YAML of the following format:
|
Based on #92 I have chosen not to use Shapely. Also given the convoluted config it appears is necessary, and the fact that this is incompatible with config flow, this whole approach of using ROI needs to be considered carefully. I am beginning to think that what is required is a separate and dedicated integration/tool for monitoring the |
I thought about the options above a bit more, and have one more idea to throw into the mix...
Essentially user supplies a mask image with a coloured zone as ROI, if centerpoint falls on a pixel of that colour, it's valid. Simple config, very flexible/multiple ROI zones... Can be implemented with PIL easily. |
That is an interesting suggestion. A person could literally use a Paint application to draw whatever regions they would want, and we would not need to do any kind of complex calculation to determine if an object is inside the region - just look up a pixel value :-) As mentioned in above comment I think this justifies a standalone integration, which could then be used by any image processing integration that outputs object locations |
We do need to be able to allow the user to reference the colour they have used in the YAML. For example, we can't always just rely only black, as some users may naturally have black areas of their camera image. Ideally they would pick a contrasting colour that is not likely to appear in the frame. Hopefully having it as a separate integration would still allow me to use it in my automations! I do motion alert -> send to rekognition -> if person count>1 send alert |
I think for the timebeing I will do:
Combining these two a person can create a wide range of ROI |
Works for me!! :) |
After more thought I think the best approach is to apply the mask to the image before processing the image |
If you are open to the masking idea - maybe the method posted above on 12th Feb will yield the most accurate results when objects are cropped by the mask |
The binary mask should be 0/1 pixel values only, this is then applied to the image before processing. The config will then simply be the path to the mask file |
Love the integration! Thanks for your work!
When my cameras detect motion, I run a snapshot image through this and generate a notification if we see a person.
Is there a way to apply multiple ROI boxes in order to build an area, or maybe an exclusion box? My path area is an odd shape, and I want to exclude the public path next to my house, as it causes people alerts that I don't want to worry about!
I'm guessing that you probably just pass these on to AWS API? :/
The text was updated successfully, but these errors were encountered: