Advertisement
MagicWinnie

Untitled

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