-
Notifications
You must be signed in to change notification settings - Fork 3
/
age_api_test.py
executable file
·65 lines (57 loc) · 1.82 KB
/
age_api_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
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
from threading import Thread
import cv2
from age_api import AgeDetection
from utils.sort import Sort
from tf_session.tf_session_runner import SessionRunner
from tf_session.tf_session_utils import Inference
import numpy as np
cap = cv2.VideoCapture(-1)
# cap = cv2.VideoCapture(videos_path.get()+'/Hitman Agent 47 - car chase scene HD.mp4')
session_runner = SessionRunner()
print("session runner created")
while True:
ret, image = cap.read()
if ret:
break
detection = AgeDetection()
detector_ip = detection.get_in_pipe()
detector_op = detection.get_out_pipe()
detection.use_session_runner(session_runner)
detection.use_threading()
session_runner.start()
detection.run()
tracker = Sort()
frame_no = 0
def read_video():
# start = time.time()
while True:
ret, image = cap.read()
if not ret:
continue
detector_ip.push(Inference(image.copy()))
t = Thread(target=read_video)
t.start()
while True:
detector_op.pull_wait()
ret, inference = detector_op.pull(True)
if ret:
i_dets = inference.get_result()
frame = np.copy(i_dets.get_image())
trackers = tracker.update(i_dets)
for trk in trackers:
bbox = trk.get_state()
ages = trk.get_ages()
genders = trk.get_genders()
ethnicity = trk.get_ethnicity()
age = sum(ages) / len(ages)
gender = np.average(np.array(genders), axis=0)
# print(ethnicity)
# ethnicity = np.argmax(np.array(ethnicity), axis=0)
# gender = np.sum()
# print(ethnicity)
# break
frame = i_dets.annotate(frame, bbox, int(age), gender, ethnicity[-1])
# cv2.imshow("crop"+str(trk.get_id()), trk.get_face())
frame_no += 1
cv2.imshow("Final Output", frame)
cv2.waitKey(1)