28 lines
819 B
Python
28 lines
819 B
Python
![]() |
import os
|
||
|
import dlib
|
||
|
from skimage import io
|
||
|
import imghdr
|
||
|
|
||
|
|
||
|
pwd = os.path.dirname(__file__)
|
||
|
result = open(pwd + '\\test-A\out.tsv', 'w')
|
||
|
|
||
|
sp = dlib.shape_predictor(pwd + '\shape_predictor_68_face_landmarks.dat')
|
||
|
facerec = dlib.face_recognition_model_v1(pwd + '\dlib_face_recognition_resnet_model_v1.dat')
|
||
|
detector = dlib.get_frontal_face_detector()
|
||
|
|
||
|
directory = input('Enter directory path:\n')
|
||
|
|
||
|
for filename in os.listdir(directory):
|
||
|
f = os.path.join(directory, filename)
|
||
|
picture = io.imread(f)
|
||
|
if imghdr.what(f) != 'png':
|
||
|
dets = detector(picture, 1)
|
||
|
for k, d in enumerate(dets):
|
||
|
fraze = "face:"+str(d.left())+","+str(d.top())+","+str(d.right())+","+str(d.bottom())+"\t"
|
||
|
result.write(fraze)
|
||
|
shape = sp(picture, d)
|
||
|
|
||
|
result.write('\n')
|
||
|
|
||
|
result.close()
|