Advertisement
sentero-esp12

Untitled

Jun 10th, 2021
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import face_alignment
  2. from face_alignment import *
  3. from skimage import io
  4. import cv2
  5. import os
  6. import json
  7.  
  8. fa = face_alignment.FaceAlignment(
  9.     face_alignment.LandmarksType._2D, device='cuda', flip_input=False)
  10.  
  11. #preds = fa.get_landmarks_from_directory('./images/1/')
  12. dir = './images/2/'
  13.  
  14.  
  15. def createLandmarks(name):
  16.     input = io.imread(dir + name)
  17.     img = cv2.cvtColor(input, cv2.COLOR_BGR2RGB)
  18.     preds = fa.get_landmarks(img)
  19.     if preds == None:
  20.         return
  21.     print(len(preds[0]))
  22.     m = [[int(preds[0][ii, 0]), int(preds[0][ii, 1])] for ii in range(68)]
  23.     print(m)
  24.     k = json.dumps(m).replace('"', '')
  25.     with open('./ready/2/' + name.replace('.jpg', '.json'), 'w', encoding='utf-8') as f:
  26.         f.write(k)
  27.  
  28. #dot = [255, 255, 255]
  29.  
  30. # for x in preds[0]:
  31. # circle:
  32. #cv2.circle(img, (int(x[0]), int(x[1])), 1, dot, -1)
  33. # dot:
  34. #img[int(x[1]), int(x[0])] = dot
  35.  
  36. #cv2.imwrite('./ready/2/' + name, img)
  37.  
  38.  
  39. # createLandmarks('00000.jpg')
  40.  
  41. for file in os.listdir(dir):
  42.     if file.endswith(".jpg"):
  43.         createLandmarks(file)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement