forked from cleardusk/3DDFA_V2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.py
executable file
·47 lines (34 loc) · 1.6 KB
/
demo.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
# coding: utf-8
__author__ = 'cleardusk'
import argparse
import cv2
import yaml
from FaceBoxes import FaceBoxes
from TDDFA import TDDFA
from utils.functions import draw_landmarks, get_suffix
from utils.tddfa_util import str2bool
def main(args):
cfg = yaml.load(open(args.config), Loader=yaml.FullLoader)
gpu_mode = args.mode == 'gpu'
tddfa = TDDFA(gpu_mode=gpu_mode, **cfg)
# Initialize FaceBoxes
face_boxes = FaceBoxes()
# Given a still image path and load to BGR channel
img = cv2.imread(args.img_fp)
# Detect faces, get 3DMM params and roi boxes
boxes = face_boxes(img)
print(f'Detect {len(boxes)} faces')
param_lst, roi_box_lst = tddfa(img, boxes)
# Visualization
ver_lst = tddfa.recon_vers(param_lst, roi_box_lst, dense_flag=args.dense_flag)
wfp = f'examples/results/{args.img_fp.split("/")[-1].replace(get_suffix(args.img_fp), "")}_dense{args.dense_flag}.jpg'
draw_landmarks(img, ver_lst, show_flg=args.show_flg, dense_flg=args.dense_flag, wfp=wfp)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='The demo of still image of 3DDFA_V2')
parser.add_argument('-c', '--config', type=str, default='configs/mb1_120x120.yml')
parser.add_argument('-f', '--img_fp', type=str)
parser.add_argument('-m', '--mode', default='cpu', type=str, help='gpu or cpu mode')
parser.add_argument('--show_flg', default='true', type=str2bool, help='whether show the visualization result')
parser.add_argument('--dense_flg', default='true', type=str2bool, help='whether reconstructing dense')
args = parser.parse_args()
main(args)