
Face Recognition and Face Detection series in Python
- Detecting Faces with 20 lines in Python
- Face Recognition with 20 lines in Python
- Detecting Facial Features with 20 lines in Python
- Facial Features and Face Recognition with 20 lines in Python
- Performance improvements with code
- Resize the camera input with OpenCV
- Working with Haar Cascades and OpenCV
- Detect and blur faces 😁 using haar cascades
- Detect and blur faces 😁 using DNN
Hi !
I’ve write a lot about how to use AI models in C# to perform tasks like Face recognition, speech analysis, and more. During the Chicago CodeCamp, someone ask me about how to perform Face Recognition in Python. I didn’t have any working sample to showcase this, and I failed in try to write a 2 min app. So I added this into my ToDo list.
For this demo I’ll use Anaconda as the base Python distribution and Visual Studio Code as the code editor. There are several packages to perform face detection in Python. I’ll use a mix between OpenCV and Adam Geitgey Face Recognition package to use the camera and detect and recognize faces.
I’ll start by installing some packages to use in python app: dlib, openCV and face_recognition
"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install dlib --user
"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install face_recognition --user
"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install opencv-python --user
And, the first step will be to detect faces and draw frames around them. All of this in 20 lines of code

When we run the app, we will see the camera feed and frames around the detected faces. In my next post I’ll add some extra code to perform face recognition.
Happy Coding!
Greetings @ Toronto
El Bruno
Resources
- Anaconda Distribution, https://www.anaconda.com/distribution/
- Visual Studio Code, https://code.visualstudio.com/
- Adam Geitgey, https://github.com/ageitgey/face_recognition
First off All, thank you for sharing your experience.
I have a question, i ran this code in my laptop and did perform well, in my desktop the application ran well, but i use only two images to recognize, if i update this to 100k images, there is a Way to optimize the processing?
Best regards
LikeLiked by 1 person
Hi Marcelo
there are a couple of techniques that you can use, like multithreading, or a smart queue system. It all depends on your complete scenario.
However a search for multithreading or queue may help !
Regards
LikeLike
Would love to chat about the basics with you, about the opencv, having issues running your code for some reason to try and learn a bit
LikeLike
Hi, I am having some trouble getting the code to run on vs code if you could email me and help me it would be much appreciated!
LikeLike
Let me know how I can help …
LikeLike