robmarkcole / HASS-Deepstack-face

Home Assistant custom component for using Deepstack face recognition
https://community.home-assistant.io/t/face-and-person-detection-with-deepstack-local-and-free/92041
MIT License
218 stars 68 forks source link

FR - Only teach a face to deepstack if a single face is detected in the picture #55

Closed zroger49 closed 3 years ago

zroger49 commented 3 years ago

Greatings. For my needs I would like that the deepstack face integration would only learn a face IF the input image to the teach_face service contains only a single face. In addition it would be nice for an event to fired when a face is taught (or when you try to teach a face. Not sure if you missing these features by design or not. Either way I have a quick and dirty implementation of this where I first scan the picture before telling deepstack to learn a face. Let me known if this is something you are interested in adding to your repository.

Something like this:

            n_face = detect_number_of_faces(image)
            if n_face == 0: 
                _LOGGER.info("No face detected in %s", file_path)
            elif n_face >= 1: 
                _LOGGER.info("Multiple faces detected in %s", file_path)
            else: 
                self._dsface.register(name, image)
                _LOGGER.info("Deepstack face taught name : %s", name)

            #Fire an event to notify the frontend 
            event_data = {
                "person_name": name, 
                "image": file_path, 
                "faces": n_face
            }
robmarkcole commented 3 years ago

Hi RE multiple faces, this could be achieved using an automation, did you try this out? I would really expect the deepstack API to return an error code in this event.

RE firing an event, I guess thats a reasonable addition if you wish to create a PR Many thanks

zroger49 commented 3 years ago

Hi,

RE multiple faces, this could be achieved using an automation, did you try this out? I would really expect the deepstack API to return an error code in this event.

As far as my testing went it did not actually. Ill do a sanity check test over the weekend, but I think it learns two faces with the same name (maybe something else is going under the hood). Since I opened this FR I refactored your code a bit, but the implementation is too specific to be useful to you

RE firing an event, I guess thats a reasonable addition if you wish to create a PR

I'll do it over the weekend

Thank you for the awesome integration

zroger49 commented 3 years ago

I retested the integration with a photo with > 2 faces, and there is no error code returned. Maybe this is something that should be fixed in the API or the python wrapper side of things an not in the actual integration.

Cheers

robmarkcole commented 3 years ago

One for deepstack API then, closing