Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from imutils import face_utils
- import os
- import cv2
- import dlib
- class Solver:
- def __init__(self, path_to_dir):
- self.predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
- for file in os.listdir(path_to_dir):
- file_name = os.path.join(path_to_dir,file)
- image = cv2.imread(file_name)
- def predict(self, path_to_file):
- image = cv2.imread(path_to_file)
- detector = dlib.get_frontal_face_detector()
- predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- rects = detector(gray, 1)
- for rect in rects:
- shape = predictor(gray, rect)
- shape = face_utils.shape_to_np(shape)
- if (shape[48][0] < shape[40][0]) and (shape[54][0] > shape[47][0]):
- return True
- else:
- return False
Add Comment
Please, Sign In to add comment