forked from neozhaoliang/surround-view-system-introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_live_demo.py
63 lines (49 loc) · 2.08 KB
/
run_live_demo.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
import os
import cv2
from surround_view import CaptureThread, CameraProcessingThread
from surround_view import FisheyeCameraModel, BirdView
from surround_view import MultiBufferManager, ProjectedImageBuffer
import surround_view.param_settings as settings
yamls_dir = os.path.join(os.getcwd(), "yaml")
camera_ids = [4, 3, 5, 6]
flip_methods = [0, 2, 0, 2]
names = settings.camera_names
cameras_files = [os.path.join(yamls_dir, name + ".yaml") for name in names]
camera_models = [FisheyeCameraModel(camera_file, name) for camera_file, name in zip(cameras_files, names)]
def main():
capture_tds = [CaptureThread(camera_id, flip_method)
for camera_id, flip_method in zip(camera_ids, flip_methods)]
capture_buffer_manager = MultiBufferManager()
for td in capture_tds:
capture_buffer_manager.bind_thread(td, buffer_size=8)
if (td.connect_camera()):
td.start()
proc_buffer_manager = ProjectedImageBuffer()
process_tds = [CameraProcessingThread(capture_buffer_manager,
camera_id,
camera_model)
for camera_id, camera_model in zip(camera_ids, camera_models)]
for td in process_tds:
proc_buffer_manager.bind_thread(td)
td.start()
birdview = BirdView(proc_buffer_manager)
birdview.load_weights_and_masks("./weights.png", "./masks.png")
birdview.start()
while True:
img = cv2.resize(birdview.get(), (300, 400))
cv2.imshow("birdview", img)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
for td in capture_tds:
print("camera {} fps: {}\n".format(td.device_id, td.stat_data.average_fps), end="\r")
for td in process_tds:
print("process {} fps: {}\n".format(td.device_id, td.stat_data.average_fps), end="\r")
print("birdview fps: {}".format(birdview.stat_data.average_fps))
for td in process_tds:
td.stop()
for td in capture_tds:
td.stop()
td.disconnect_camera()
if __name__ == "__main__":
main()