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.51k stars 155 forks source link

Feature/added detect_remote_faces to face_recognition domain #605

Open pierluigizagaria opened 1 year ago

pierluigizagaria commented 1 year ago

Adds detect_remote_faces to face_recognition domain. The purpose of the config is to enable the face_recognition components to detect faces that are trained in other ways as I mentioned in #604

For example in my case I would like to continue train Compreface using the native UI. I wanted to make this config available only for Compreface but was difficult for me on how the logic is currently implemented. Then I thought that this behavior could be useful even on other face recognition components.

This PR also fixes the error occured in #603 by checking the existence of the train dir.

netlify[bot] commented 1 year ago

Deploy Preview for viseron ready!

Name Link
Latest commit 1467d4aa6ca20be8bee939210e44df19e65f4706
Latest deploy log https://app.netlify.com/sites/viseron/deploys/6462330abfe0600008a6bbe9
Deploy Preview https://deploy-preview-605--viseron.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

sonarcloud[bot] commented 1 year ago

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
6.6% 6.6% Duplication

roflcoopter commented 1 year ago

Awesome, thanks! Will have a look at the code in the coming days

roflcoopter commented 1 year ago

I think you have to do some changes in order for this to work correctly. Calling vis.add_entity each time a face is recognized wont work well, as it will add a new entity each time a persons face is recognized.

I think the best way is to call an API endpoint here: https://github.com/roflcoopter/viseron/blob/dev/viseron/domains/face_recognition/__init__.py#L90 which lists each face and you can then create entities the same way as it works for the file system. You can create an abstract method in that class that the subclass in the compreface component can override which should return a list of names to track. This will also allow components which cant support this feature (dlib for instance) to simply not implement this method and instead log an error saying it is unsupported.

It is also a good idea to move the detect_remote_faces option into the BASE_CONFIG_SCHEMA here: https://github.com/roflcoopter/viseron/blob/dev/viseron/domains/face_recognition/__init__.py#L36 Then you dont have to duplicate it on all components.

Let me know if i need to explain further!

pierluigizagaria commented 1 year ago

I added a comment. When timer expires face is not removed from the _faces dict. This prevent the registration of the entity on every detection. I thought about calling the api but the problem was that new faces trained would require a restart of Viseron to re-register the component and download the new faces

roflcoopter commented 1 year ago

Ahh i see now. I still think it would be better to fetch them during startup so it behaves like locally trained faces. We could add a way to refresh the faces using the GUI/API in the future. Maybe even refresh automatically on an interval