MagicWinnie

Untitled

Jan 11th, 2019 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. from imutils import face_utils
  2. import os
  3. import cv2
  4. import dlib
  5. class Solver:
  6.       def __init__(self, path_to_dir):
  7.             self.predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
  8.             for file in os.listdir(path_to_dir):
  9.                   file_name = os.path.join(path_to_dir,file)
  10.                   image = cv2.imread(file_name)
  11.       def predict(self, path_to_file):
  12.             image = cv2.imread(path_to_file)
  13.             detector = dlib.get_frontal_face_detector()
  14.             predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
  15.             gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  16.             rects = detector(gray, 1)
  17.             for rect in rects:
  18.                   shape = predictor(gray, rect)
  19.                   shape = face_utils.shape_to_np(shape)
  20.             if (shape[48][0] < shape[40][0]) and (shape[54][0] > shape[47][0]):
  21.                   return True
  22.             else:
  23.                   return False
Add Comment
Please, Sign In to add comment