-
Notifications
You must be signed in to change notification settings - Fork 43
/
demo_video.py
53 lines (38 loc) · 1.51 KB
/
demo_video.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
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import argparse
import service
import cv2
def main(args, color=(224, 255, 255)):
fd = service.UltraLightFaceDetecion("weights/RFB-320.tflite",
conf_threshold=0.95)
if args.mode in ["sparse", "pose"]:
fa = service.DepthFacialLandmarks("weights/sparse_face.tflite")
else:
fa = service.DenseFaceReconstruction("weights/dense_face.tflite")
if args.mode == "mesh":
color = service.TrianglesMeshRender("asset/render.so",
"asset/triangles.npy")
handler = getattr(service, args.mode)
cap = cv2.VideoCapture(args.filepath)
while True:
ret, frame = cap.read()
if not ret:
break
# face detection
boxes, scores = fd.inference(frame)
# raw copy for reconstruction
feed = frame.copy()
for results in fa.get_landmarks(feed, boxes):
handler(frame, results, color)
# cv2.imwrite(f'draft/gif/trans/img{counter:0>4}.jpg', frame)
cv2.imshow("demo", frame)
if cv2.waitKey(1) == ord("q"):
break
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Video demo script.")
parser.add_argument("-f", "--filepath", type=str, required=True)
parser.add_argument("-m", "--mode", type=str, default="sparse",
choices=["sparse", "dense", "mesh", "pose"])
args = parser.parse_args()
main(args)