File size: 1,114 Bytes
0f691e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python #encoding:utf-8
import torch
import pickle
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image

import cv2
import os
import face_alignment
from skimage import io, transform

fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D,device='cuda:0', flip_input=False)


Nums = 0
FilePath = '../TestData/RealVgg/Imgs'
SavePath = '../TestData/RealVgg/Imgs/Landmarks'
if not os.path.exists(SavePath):
    os.mkdir(SavePath)

ImgNames = os.listdir(FilePath)
ImgNames.sort()

for i,name in enumerate(ImgNames):
    print((i,name))

    imgs = io.imread(os.path.join(FilePath,name))

    imgO = imgs
    try:
        PredsAll = fa.get_landmarks(imgO)
    except:
        print('#########No face')
        continue
    if PredsAll is None:
        print('#########No face2')
        continue
    if len(PredsAll)!=1:
        print('#########too many face')
        continue
    preds = PredsAll[-1]
    AddLength = np.sqrt(np.sum(np.power(preds[27][0:2]-preds[33][0:2],2)))
    SaveName = name+'.txt'

    np.savetxt(os.path.join(SavePath,SaveName),preds[:,0:2],fmt='%.3f')