Advertisement
MagicWinnie

Untitled

Jan 6th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. from imutils import face_utils
  2. import numpy as np
  3. import argparse
  4. import imutils
  5. import dlib
  6. import cv2
  7. import math
  8. def rass(x1,y1,x2,y2):
  9.       return math.sqrt((x2-x1)**2+(y2-y1)**2)
  10. #-------------------------------------
  11. fac=[]    
  12. inp=list(map(int,input().split(' ')))
  13. detector = dlib.get_frontal_face_detector()
  14. predictor = dlib.shape_predictor(r'C:\Users\magic\Documents\facial-landmarks\facial-landmarks\shape_predictor_68_face_landmarks.dat')
  15. for photo in inp:
  16.       image = cv2.imread('faces/'+str(photo)+'.jpg')
  17.       gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  18.       rects = detector(gray, 1)
  19.       for (i, rect) in enumerate(rects):
  20.             shape = predictor(gray, rect)
  21.             shape = face_utils.shape_to_np(shape)
  22.       #------------------------------------------------
  23.       one=rass(shape[37][0],shape[37][1],shape[41][0],shape[41][1])
  24.       two=rass(shape[38][0],shape[38][1],shape[40][0],shape[40][1])
  25.       three=rass(shape[43][0],shape[43][1],shape[47][0],shape[47][1])
  26.       four=rass(shape[44][0],shape[44][1],shape[46][0],shape[46][1])
  27.       usras=(one+two+three+four)/4
  28.       last=rass(shape[27][0],shape[27][1],shape[8][0],shape[8][1])
  29.       res=usras/last
  30.       fac.append(res)
  31. print(inp[fac.index(max(fac))],inp[fac.index(min(fac))])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement