加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
run_live_demo.py 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
zemora 提交于 2020-07-15 11:57 . add all code
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化