forked from affinelayer/pix2pix-tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
face_landmark_detect_batch.py
70 lines (44 loc) · 1.76 KB
/
face_landmark_detect_batch.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import os
import argparse
import cv2
#import dlib
import face_landmark_detect
def face_landmark_detect_batch(input_dir, output_dir, blend, *args):
print("Start Batch Processing.\n")
#iterate through directory
for f in os.listdir(input_dir):
input_file = os.path.join(input_dir, f)
output_file = os.path.join(output_dir, f)
print("Processing file: {}".format(input_file))
#load image
#img = dlib.load_rgb_image(input_file)
img = cv2.imread(input_file, 1)
img_res = img.shape[0]
#create bg image first outside loop
bg_img = face_landmark_detect.create_bg(img_res)
#run detection function
out_img = face_landmark_detect.face_landmark_detect(img, bg_img, img_res, blend)
#write image
cv2.imwrite(output_file, out_img)
print("Face Landmark Image written:", output_file, "\n")
print("Batch Processing Finished.\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = "Batch Face Landmark Detection")
parser.add_argument('-i', '--input_dir',
dest='input_dir',
help='Face Input Directory',
required=True)
parser.add_argument('-o', '--output_dir',
dest='output_dir',
help='Output Directory',
required=True)
parser.add_argument('-b', '--blend',
dest='blend',
help='Blend Original',
default=0,
type=int,
required=False)
r = parser.parse_args()
#call function
face_landmark_detect_batch(r.input_dir, r.output_dir, r.blend)