-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_landmarks.py
executable file
·49 lines (40 loc) · 1.36 KB
/
get_landmarks.py
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
import os
import cv2
import click
import tqdm
import re
import numpy as np
from TalkingFace.get_disentangle_landmarks import DisentangledLandmarks
@click.command()
@click.option('--from_path')
@click.option('--to_path')
@click.option('--shutup', is_flag = True)
@click.option('--norm', is_flag = True)
def get_landmarks(from_path,
to_path,
shutup,
norm
):
"""get landmarks
"""
to_save_ldm_list = []
landmarks_func = DisentangledLandmarks()
if shutup:
to_save_ldm_list = [landmarks_func(None) for _ in range(250)]
np.save(to_path, np.concatenate(to_save_ldm_list, axis = 0))
return
#assert os.path.isdir(from_path), "expected from_path is directory."
assert to_path.endswith('npy'), "expected to_path postfix is numpy-like."
# sorted files
files = os.listdir(from_path)
files = sorted(files, key = lambda x: int(''.join(re.findall('[0-9]+', x))))
files = [os.path.join(from_path, x) for x in files]
p_bar = tqdm.tqdm(files)
for _file in p_bar:
image = cv2.imread(_file)
assert image is not None, f"{_file} not exists."
ldm = landmarks_func(image)
to_save_ldm_list.append(ldm)
np.save(to_path, np.concatenate(to_save_ldm_list, axis = 0))
if __name__ == '__main__':
get_landmarks()