-
-
Save ageitgey/82d0ea0fdb56dc93cb9b716e7ceb364b to your computer and use it in GitHub Desktop.
| import sys | |
| import dlib | |
| import cv2 | |
| import openface | |
| # You can download the required pre-trained face detection model here: | |
| # http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 | |
| predictor_model = "shape_predictor_68_face_landmarks.dat" | |
| # Take the image file name from the command line | |
| file_name = sys.argv[1] | |
| # Create a HOG face detector using the built-in dlib class | |
| face_detector = dlib.get_frontal_face_detector() | |
| face_pose_predictor = dlib.shape_predictor(predictor_model) | |
| face_aligner = openface.AlignDlib(predictor_model) | |
| # Take the image file name from the command line | |
| file_name = sys.argv[1] | |
| # Load the image | |
| image = cv2.imread(file_name) | |
| # Run the HOG face detector on the image data | |
| detected_faces = face_detector(image, 1) | |
| print("Found {} faces in the image file {}".format(len(detected_faces), file_name)) | |
| # Loop through each face we found in the image | |
| for i, face_rect in enumerate(detected_faces): | |
| # Detected faces are returned as an object with the coordinates | |
| # of the top, left, right and bottom edges | |
| print("- Face #{} found at Left: {} Top: {} Right: {} Bottom: {}".format(i, face_rect.left(), face_rect.top(), face_rect.right(), face_rect.bottom())) | |
| # Get the the face's pose | |
| pose_landmarks = face_pose_predictor(image, face_rect) | |
| # Use openface to calculate and perform the face alignment | |
| alignedFace = face_aligner.align(534, image, face_rect, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE) | |
| # Save the aligned image to a file | |
| cv2.imwrite("aligned_face_{}.jpg".format(i), alignedFace) | |
I want to add to nitish11's comment above on installing openface. His instructions worked for me. I am using Anaconda (though that may not be necessary).
Opened command window from Anaconda.
Installed git using "conda install -c anaconda git".
Then executed nitish11's steps. Did not need to use sudo.
To install openface, follow the below instructions:
- git clone https://github.com/cmusatyalab/openface.git
- cd openface
- pip install -r requirements.txt
- sudo python setup.py install
To download the trained model:
- sh models/get-models.sh
Thank you
I have installed openface but when I got an error just like below when I run it :
Traceback (most recent call last):
File "step2.py", line 16, in <module>
face_aligner = openface.AlignDlib(predictor_model)
AttributeError: module 'openface' has no attribute 'AlignDlib'
note: the step2.py is the script. My system: ubuntu 20.04
how I supose do?
The problem that I'm experiencing is different:
24 # Run the HOG face detector on the image data ---> 25 detected_faces = face_detector(image, 1) 26 27 print("Found {} faces in the image file {}".format(len(detected_faces), file_name))RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
I've tried all that is suggested in ageitgey/face_recognition#21 ,but couldn't fix it. Please help! Thank you!
hi get try
image.astype('uint8')
Hey where can I find full project
PLEASE give the link