- Improved console UI with console-menu
- Uses selenium to crawl actors' images as dataset
- Opens default file explorer for different OSs to choose the file
Recognizing actors in a movie clip or image, using DeepLearning and Python. Can use either CNN or HOG for face detection and then compare the face with our dataset of faces.
Here I've used Spiderman 2 (2004), as an example. It can work with any piece of media, given the right dataset.
Tons of help from ageitgey's face_recognition library.
Inspired by this wonderful article.
-
The dataset has the following structure, containing actor images collected using the Bing Image API (getData.py).
As I'm using Spiderman 2, I've collected several pictures of the actors in the movie. Per actor I have ~15 images. More will do better, but this number seems to work fine.
-
For every image in the dataset, we first get a square enclosing the face in the image, then generate a 128d vector for that face, which is dumped to the 'encodings.pickle' file.
We can either use CNN(slower, more accurate) or HOG(faster, less accurate) for the face detection process. Here I've used the face_recognition library, which gives me both the options.
-
Consider an image, be it a still from the movie, or a frame of a video clip. First, we identify the faces in the image using the same method as above (CNN or HOG), generate an encoding for it(128d vector), and then compare it with our collected encodings. The actors with the most matched encodings is the actor in the image.
Read the first few lines of the Python file involved to understand the parameters used in each case
-
python faceEncode.py --dataset dataset/actors --encodings encodings.pickle -d hog
-
python faceRecImage.py -e encodings.pickle -i examples/ex6.png -d hog
-
python faceRecVideoFile.py -e encodings.pickle -i input_vids/ex2.mp4 -o output_vids/ex2.mp4 -y 0 -d hog
Outputs a video with the faces marked.
-
python faceRecVideo.py -e encodings.pickle -o output_vids/ex1.avi -y 0 -d hog
-
python getData.py --query "tobey macguire" --output dataset/tobey_macquire
Will fetch images from Bing Image Search and save in the mentioned directory (Max 50). Make sure to get your own Bing search API key from here and fill it up in the code.