Learn new faces in OpenCV


is OpenCV capable to learn new faces?
I have a set of trained faces, but i want that new faces get an permanent id.

The story behind this is, that i want to do some magic for a face once.
But an untrained face fires this code everytime it will be detected.

Thanks for advice.

this is a pretty good introduction (with code) to what you are looking for https://www.learnopencv.com/face-recognition-an-introduction-for-beginners/

I havn’t tried it on the nano but can’t see any reason it wont work.

Hi moshe.livne,

in my scenario i grab the videostream from my ip-cam.
OpenCV is trained with the people who are living in this house.
When someone untrained people come into this house, opencv detects this people as unknown and creates a dataset with some facial attributes.
This dataset should be created once for each face, so i have to make sure, that opencv detects this face next time not as unknown.

yes, the code in the link contains what you need. see 3.3

Hello Moshe.livne,

thanks for the link. I downloaded the zip file with a lot of code samples inside, but i had trouble to find the right example which includes the code for chapter 3.3.

Please can you tell me where i can find the right code?

Thanks a lot and best regards

Apologies, i missed the part that it was introduction and the rest will be in followup articles.
You can try https://www.pyimagesearch.com/2018/09/24/opencv-face-recognition/ . Adrians code is very clear and well explained. Again, I have not tried it myself, and the enrollment process seems to be somewhat disconnected from the flow but I hope you can gather enough from it.

I really had no opportunity to do facial recognition so can’t help you beyond things I remembered seeing…


thank you for the link.
I already knew this post and tried it by myself, but i had some performance issues, which i descriped here https://devtalk.nvidia.com/default/topic/1051927/jetson-nano/runtimewarning-in-face_recognition/post/5340646/#5340646.
Face recognition works very well for me with the CNN approach.

But this post don’t seems to descripe a feature like a database update (3.3. enroll new faces).
This is exactly what i want.

Thank you and best regards

as for performance, you need to load the images from the camera in parallel to the execution of the detector, this way you will get constant fps (more or less :) ). same site has an tutorial on this (look for FPS), unfortunately with a small bug.

as for enrolling, you just need to add the embedding to your database, that should be all…
just add the new face to the embeddings and names lists, pickle.dump your data and bob is you uncle

note: as i said, i am not in a face recognition phase now, so all this is just from reading the code.