-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy paths4_p3_test_mi10_tex_objs_video.py
More file actions
78 lines (74 loc) · 3.26 KB
/
Copy paths4_p3_test_mi10_tex_objs_video.py
File metadata and controls
78 lines (74 loc) · 3.26 KB
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
# Author: Yulin Wang (yulinwang@seu.edu.cn)
# School of Mechanical Engineering, Southeast University, China
import cv2, os, sys
import numpy as np
from HccePose.bop_loader import bop_dataset
from HccePose.test_script_utils import print_stage_time_breakdown
from HccePose.tester import Tester
if __name__ == '__main__':
sys.path.insert(0, os.getcwd())
current_dir = os.path.dirname(sys.argv[0])
dataset_path = os.path.join(current_dir, 'demo-tex-objs')
test_video_path = os.path.join(current_dir, 'test_videos')
bop_dataset_item = bop_dataset(dataset_path)
obj_ids = bop_dataset_item.obj_id_list
CUDA_DEVICE = '0'
hccepose_vis = True
hccepose_acceleration = 'pytorch'
save_visualizations = hccepose_vis
print_stage_timing = False
Tester_item = Tester(bop_dataset_item, hccepose_vis = hccepose_vis, CUDA_DEVICE=CUDA_DEVICE, hccepose_acceleration=hccepose_acceleration)
for name in ['VID_20251009_141606',
'VID_20251009_141731',
'VID_20251009_141754',
'VID_20251009_141902',
'VID_20251009_141948']:
file_name = os.path.join(test_video_path, '%s.mp4'%name)
cap = cv2.VideoCapture(file_name)
fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out_1 = None
out_2 = None
cam_K = np.array([
[1.63235512e+03, 0.00000000e+00, 9.74032712e+02],
[0.00000000e+00, 1.64159967e+03, 5.14229781e+02],
[0.00000000e+00, 0.00000000e+00, 1.00000000e+00],
])
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
results_dict = Tester_item.predict(cam_K, frame, obj_ids,
conf = 0.85, confidence_threshold = 0.85)
print_stage_time_breakdown(results_dict, enabled=print_stage_timing, prefix='%s frame' % name)
fps_hccepose = 1 / results_dict['time']
if not save_visualizations:
continue
show_6D_vis1 = results_dict['show_6D_vis1']
show_6D_vis1[show_6D_vis1 < 0] = 0
show_6D_vis1[show_6D_vis1 > 255] = 255
if out_1 is None:
out_1 = cv2.VideoWriter(
file_name.replace('.mp4', '_show_1.mp4'),
fourcc,
fps,
(show_6D_vis1.shape[1], show_6D_vis1.shape[0])
)
out_1.write(show_6D_vis1.astype(np.uint8))
show_6D_vis2 = results_dict['show_6D_vis2']
show_6D_vis2[show_6D_vis2 < 0] = 0
show_6D_vis2[show_6D_vis2 > 255] = 255
if out_2 is None:
out_2 = cv2.VideoWriter(
file_name.replace('.mp4', '_show_2.mp4'),
fourcc,
fps,
(show_6D_vis2.shape[1], show_6D_vis2.shape[0])
)
cv2.putText(show_6D_vis2, 'FPS: {0:.2f}'.format(fps_hccepose), (20, 60), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 4, cv2.LINE_AA)
out_2.write(show_6D_vis2.astype(np.uint8))
cap.release()
if out_1 is not None:
out_1.release()
if out_2 is not None:
out_2.release()