Skip to content

Instantly share code, notes, and snippets.

@atsui888
Created February 16, 2018 04:02
Show Gist options
  • Save atsui888/764dc3813f79501617b187d2036b8179 to your computer and use it in GitHub Desktop.
Save atsui888/764dc3813f79501617b187d2036b8179 to your computer and use it in GitHub Desktop.
import dlib, cv2, os
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
def generateText(filename):
final_array = []
img = cv2.imread(filename)
img_resize = img
rects = detector(img_resize, 1)
for i, rect in enumerate(rects):
shape = predictor(img_resize, rect)
for x in range(68):
final_array.append([shape.part(x).x, shape.part(x).y])
open(filename+'.txt', 'w').write('\n'.join(map(lambda x: str(x).replace("[","").replace("]","").replace(',',''), final_array)))
def getTextsForFolder(foldername):
for file in os.listdir(foldername):
if file.endswith(".jpg"):
print(file)
generateText(foldername+'/'+str(file))
getTextsForFolder("SourcePics")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment