Skip to content

Commit 98b48b6

Browse files
committedAug 23, 2022
Update visualise.py
1 parent c75e51d commit 98b48b6

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed
 

‎code/visualise.py

+47-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import pickle
23
import re
34
from collections import defaultdict
@@ -8,6 +9,39 @@
89
import numpy as np
910
import cv2
1011

12+
activity2id = {
13+
"BG": 0, # background
14+
"activity_walking": 1,
15+
"activity_standing": 2,
16+
"activity_carrying": 3,
17+
"activity_gesturing": 4,
18+
"Closing": 5,
19+
"Opening": 6,
20+
"Interacts": 7,
21+
"Exiting": 8,
22+
"Entering": 9,
23+
"Talking": 10,
24+
"Transport_HeavyCarry": 11,
25+
"Unloading": 12,
26+
"Pull": 13,
27+
"Loading": 14,
28+
"Open_Trunk": 15,
29+
"Closing_Trunk": 16,
30+
"Riding": 17,
31+
"specialized_texting_phone": 18,
32+
"Person_Person_Interaction": 19,
33+
"specialized_talking_phone": 20,
34+
"activity_running": 21,
35+
"PickUp": 22,
36+
"specialized_using_tool": 23,
37+
"SetDown": 24,
38+
"activity_crouching": 25,
39+
"activity_sitting": 26,
40+
"Object_Transfer": 27,
41+
"Push": 28,
42+
"PickUp_Person_Vehicle": 29,
43+
}
44+
1145

1246
def get_person_box_at_frame(tracking_results, target_frame_idx):
1347
"""Get all the box from the tracking result at frameIdx."""
@@ -86,12 +120,11 @@ def visualise(args):
86120
with open(args.pred_path, "rb") as f:
87121
pred_data = pickle.load(f)
88122
pred_data = {
89-
k: v for k, v in pred_data.items() if k in ['obs_list', 'pred_gt_list', 'pred_list']
123+
k: v for k, v in pred_data.items() if k in ['seq_ids', 'obs_list', 'pred_gt_list', 'pred_list', 'pred_act']
90124
}
91125

92126
video_dict = get_video_dict(pred_data)
93-
94-
del pred_data['act_pred_list']
127+
id2activity = {v:k for k,v in activity2id.items()}
95128
for video_name in video_dict:
96129
video_file = os.path.join(args.video_base, video_name + '.mp4')
97130

@@ -117,7 +150,7 @@ def visualise(args):
117150
#
118151
#
119152
# print(seq_id, video_meta)
120-
cur_frame = -1
153+
cur_frame = - 8 * args.drop_frame
121154
next_signal = False
122155
while cur_frame < video_meta["frame_count"]:
123156
cur_frame += 1
@@ -131,15 +164,21 @@ def visualise(args):
131164

132165
for idx in filter_pred(video_pred_data, video_name + f'_{cur_frame}_+'):
133166
seq_id = video_pred_data['seq_ids'][idx]
134-
obs_traj = video_pred_data['obs_traj_list'][idx]
135-
pred_traj = video_pred_data['pred_traj_list'][idx]
136-
gt_traj = video_pred_data['gt_traj_list'][idx]
137-
167+
obs_traj = video_pred_data['obs_list'][idx]
168+
pred_traj = video_pred_data['pred_list'][idx]
169+
gt_traj = video_pred_data['pred_gt_list'][idx]
170+
# pred_act =sigmoid(np.array( video_pred_data['pred_act'][idx] * 20 ))
171+
pred_act = video_pred_data['pred_act'][idx]
138172
frame = cv2.resize(frame, (1920, 1080))
139173
frame = plot_traj(frame, obs_traj, (255, 0, 0))
140174
frame = plot_traj(frame, pred_traj, (0, 255, 0))
141175
frame = plot_traj(frame, gt_traj, (0, 0, 255))
176+
act_ids = np.nonzero( pred_act > 0.7)[0]
177+
print(act_ids)
178+
msg = ','.join([id2activity[id] for id in act_ids])
142179

180+
frame = cv2.putText(frame,msg, (int(obs_traj[-1,0]), int(obs_traj[-1,1])),cv2.FONT_HERSHEY_SIMPLEX,
181+
1, (255, 0, 0), 1, cv2.LINE_AA )
143182
# center = obs_traj[-1].astype("int")
144183
# frame = frame[center[1] - 200: center[1] + 200, center[0] - 200: center[0] + 200]
145184
frame = cv2.putText(frame, video_name + ' ' + 'frame ' + str(cur_frame), (30,30), cv2.FONT_HERSHEY_SIMPLEX,

0 commit comments

Comments
 (0)