forked from JuliusSuryaS/pytorch_cpp_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3
52 lines (46 loc) · 1.97 KB
/
3
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
48
49
50
51
52
import os, sys
import face_alignment
import skimage as io
def predict_and_save(frontal, profile, landmark_path, landmark_profile_path):
print(frontal, profile)
print(landmark_path, landmark_profile_path)
# Run the 3D face alignment on a test image, without CUDA.
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._3D, enable_cuda=False, flip_input=False,use_cnn_face_detector=True)
frontal_img = io.imread(frontal)
profile_img = io.imread(profile)
frontal_landmark = fa.get_landmarks(frontal_img)[-1]
profile_landmark = fa.get_landmarks(profile_img)[-1]
#print(preds[0,0])
#print(preds[0,1])
#print(preds[67,0])
#write to txt
print(landmark_path)
file=open(landmark_path,'w')
for i in range(0,68):
file.write("%d " %frontal_landmark[i,0])
file.write("%d" %frontal_landmark[i,1])
if i != 67:
file.write("\n")
file.close()
print(landmark_profile_path)
file=open(landmark_profile_path,'w')
for i in range(0,68):
file.write("%d " %profile_landmark[i,0])
file.write("%d" %profile_landmark[i,1])
if i != 67:
file.write("\n")
file.close()
base_path = "D:/current_project/RBF/RBF_Modeling/texturemap/"
frontal_path = base_path + "IVCL_FaceData_renamed/image/"
profile_path = base_path + "IVCL_FaceData_renamed/images_profile/"
landmark_frontal_path = base_path + "IVCL_FaceData_renamed/landmarks_dnn/"
landmark_profile_path = base_path + "IVCL_FaceData_renamed/landmarks_dnn_profile/"
for root, dirs, files in os.walk(frontal_path):
for name in files:
base_name = name.split(".")
frontal_img_path = os.path.join(frontal_path, name)
profile_img_path = os.path.join(profile_path, name)
landmark_save = os.path.join(landmark_frontal_path, base_name[0] + '.txt')
landmark_profile_save = os.path.join(landmark_profile_path, base_name[0] + '.txt')
print(landmark_save)
print(landmark_profile_save)