Interactive Face Recognition with OpenCV
OpenCV, PyImageSearch, and Facial Landmark Detection
OpenCV is a computer vision library for Python, C++, C, and Java that is commonly used in data science when working with images. People have created great tutorials and supporting programs, for example PyImageSearch. PyImageSearch has a facial landmark detector for Python that doesn’t just do facial recognition, but identifies the location and shape of the parts of the face. This enables us to do some fun things.
The landmarks are indicated with red dots:
The landmarks can be used to track specific parts of the face. Here I’m only showing the eye landmarks:
This allowed me to track the eyes. I took the average of the left and right eye landmarks to get the positions of the center of the eyes.
Next, we can do image manipulation in OpenCV. We can rotate, move, and resize images, as well as detect colors and mask them. With the masking, we can overlay images that we’ve manipulated. Starting with an image of “deal with it” glasses, we can resize, rotate, and move it relative to where the eyes are. The image of the glasses can then be overlayed on the face by using masking.
Although the glasses are supposed to drop, so I just added in that feature: