-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathposeinferscheduler.py
100 lines (77 loc) · 2.8 KB
/
poseinferscheduler.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import threading
import time
import copy
from pose3dmodules import *
class PoseInferScheduler:
def __init__(self, net, stride, upsample_ratio, cpu):
self.net = net
self.height = 0
self.stride = stride
self.upsample_ratio = upsample_ratio
self.cpu = cpu
self.left_img = None
self.right_img = None
self.exit_flag = False
self.infer_thread = None
self.img_lock = threading.Lock()
self.pose_lock = threading.Lock()
self.l_pose = None
self.r_pose = None
self.l_pose_img = None
self.r_pose_img = None
self.r_newpose = False
self.l_newpose = False
def stop_infer(self):
self.exit_flag = True
self.infer_thread.join()
print("stopping infering thread")
def start_infer(self):
self.exit_flag = False
self.infer_thread = threading.Thread(target=self.infer_pose_loop)
self.infer_thread.start()
print("infering thread started")
def infer_pose_loop(self):
while True:
if self.exit_flag:
break
if self.left_img is None or self.right_img is None:
time.sleep(1)
continue
self.img_lock.acquire()
l_img = copy.deepcopy(self.left_img)
r_img = copy.deepcopy(self.right_img)
height = l_img.shape[0]
self.img_lock.release()
l_pose_t = infer_fast(self.net, l_img, height, self.stride, self.upsample_ratio, self.cpu)
r_pose_t = infer_fast(self.net, r_img, height, self.stride, self.upsample_ratio, self.cpu)
self.pose_lock.acquire()
self.l_pose = copy.deepcopy(l_pose_t)
self.r_pose = copy.deepcopy(r_pose_t)
self.l_pose_img = copy.deepcopy(l_img)
self.r_pose_img = copy.deepcopy(r_img)
self.l_newpose = True
self.r_newpose = True
self.pose_lock.release()
print("infering thread stopped")
def set_images(self, l_img, r_img):
self.img_lock.acquire()
self.left_img = l_img
self.right_img = r_img
self.height = self.left_img.shape[0]
self.img_lock.release()
def get_left_pose(self):
self.pose_lock.acquire()
pose = copy.deepcopy(self.l_pose)
img = copy.deepcopy(self.l_pose_img)
posestatus = self.l_newpose
self.pose_lock.release()
self.l_newpose = False
return posestatus, pose, img
def get_right_pose(self):
self.pose_lock.acquire()
pose = copy.deepcopy(self.r_pose)
img = copy.deepcopy(self.r_pose_img)
posestatus = self.r_newpose
self.pose_lock.release()
self.r_newpose = False
return posestatus, pose, img