Created
February 12, 2019 14:36
-
-
Save raasoft/4a60272c422423a702d16c76d6aa56cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dlib | |
import Image | |
from skimage import io | |
import matplotlib.pyplot as plt | |
def detect_faces(image): | |
# Create a face detector | |
face_detector = dlib.get_frontal_face_detector() | |
# Run detector and get bounding boxes of the faces on image. | |
detected_faces = face_detector(image, 1) | |
face_frames = [(x.left(), x.top(), | |
x.right(), x.bottom()) for x in detected_faces] | |
return face_frames | |
# Load image | |
img_path = 'test.jpg' | |
image = io.imread(img_path) | |
# Detect faces | |
detected_faces = detect_faces(image) | |
# Crop faces and plot | |
for n, face_rect in enumerate(detected_faces): | |
face = Image.fromarray(image).crop(face_rect) | |
plt.subplot(1, len(detected_faces), n+1) | |
plt.axis('off') | |
plt.imshow(face) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment