Member-only story
Real-Time Facial Recognition with Python
One of the first computer vision projects I remember being really stoked about was object detection. More specifically, face detection. The excitement I felt when I was able to extend what I had just learned to detect objects in real time was palpable. I remember calling my mom and my sister to try out my program once I got it working and I was positively beaming. This is a quick post showcasing how to write a real-time face/eye tracking routine in Python with OpenCV and a webcam.
Facial Recognition
The basic code structure/steps needed to use OpenCV to detect objects in real time with a webcam are as follows:
- Specify the classifier model to be used
- Initiate a video capture instance
- Start a loop that will analyze every video frame as it comes
- Convert the recorded image to gray scale
- Perform the object detection using the classifer
- Draw rectangles around the detected objects
You can see the code I used for the face detection below.
The classifier I used was a built-in model of OpenCV located within the HaarCascades. These classifiers can be…