-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtest.py
38 lines (32 loc) · 988 Bytes
/
test.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
import glob
import os
import cv2
import time
import face_detection
def draw_faces(im, bboxes):
for bbox in bboxes:
x0, y0, x1, y1 = [int(_) for _ in bbox]
cv2.rectangle(im, (x0, y0), (x1, y1), (0, 0, 255), 2)
if __name__ == "__main__":
impaths = "images"
impaths = glob.glob(os.path.join(impaths, "*.jpg"))
detector = face_detection.build_detector(
"DSFDDetector",
max_resolution=1080
)
for impath in impaths:
if impath.endswith("out.jpg"): continue
im = cv2.imread(impath)
print("Processing:", impath)
t = time.time()
dets = detector.detect(
im[:, :, ::-1]
)[:, :4]
print(f"Detection time: {time.time()- t:.3f}")
draw_faces(im, dets)
imname = os.path.basename(impath).split(".")[0]
output_path = os.path.join(
os.path.dirname(impath),
f"{imname}_out.jpg"
)
cv2.imwrite(output_path, im)