Intel Realsense D435 如何通过摄像头序列号获取指定摄像头的帧集对?
生活随笔
收集整理的這篇文章主要介紹了
Intel Realsense D435 如何通过摄像头序列号获取指定摄像头的帧集对?
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
需要先創(chuàng)建上下文管理器對象,通過該對象去獲取已連接攝像頭設(shè)備的序列號。
當(dāng)然也可以直接指定攝像頭的序列號,通過config.enable_device(ds5_serial)即可啟動它。
如果不指定,則默認啟動下標為[0]的那個攝像頭。
使用序列號啟動單個攝像頭
# -*- encoding: utf-8 -*- """ @File : test_191125_根據(jù)攝像頭序列號調(diào)用指定攝像頭.py @Time : 2019/11/25 8:53 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import pyrealsense2 as rs import numpy as np import cv2 as cvpipeline = rs.pipeline() config = rs.config()ctx = rs.context()# if len(ctx.devices) > 0: # for d in ctx.devices: # print('Found device: ', # d.get_info(rs.camera_info.name), ' ', # d.get_info(rs.camera_info.serial_number)) # else: # print("No Intel Device connected")# 通過程序去獲取已連接攝像頭序列號 # ds5_serial = ctx.devices[0].get_info(rs.camera_info.serial_number) # 直接指定攝像頭序列號 ds5_serial = '827312070790'print('啟動的攝像頭序列號:{}'.format(ds5_serial))config.enable_device(ds5_serial) config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)# Start streaming pipeline.start(config) try:while True:frames = pipeline.wait_for_frames()color_frame = frames.get_color_frame()depth_frame = frames.get_depth_frame()if not depth_frame or not color_frame:continuecolor_image = np.asanyarray(color_frame.get_data())depth_image = np.asanyarray(depth_frame.get_data())window = cv.namedWindow('window', cv.WINDOW_AUTOSIZE)cv.imshow('window', color_image)cv.waitKey(1) finally:pipeline.stop()使用攝像頭序列號同時啟動兩個攝像頭
# -*- encoding: utf-8 -*- """ @File : test_191125_嘗試不使用多線程而使用序列號同時調(diào)用多個攝像頭.py @Time : 2019/11/25 14:03 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import pyrealsense2 as rs import numpy as np import cv2 as cvpipeline_0 = rs.pipeline() pipeline_1 = rs.pipeline()config_0 = rs.config() config_1 = rs.config()ctx = rs.context()# 通過程序去獲取已連接攝像頭序列號 serial_0 = ctx.devices[0].get_info(rs.camera_info.serial_number) serial_1 = ctx.devices[1].get_info(rs.camera_info.serial_number) # 直接指定攝像頭序列號 # ds5_serial = '827312070790'# print('啟動的攝像頭序列號:{}'.format(ds5_serial))config_0.enable_device(serial_0) config_1.enable_device(serial_1) config_0.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) config_0.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) config_1.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) config_1.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)# Start streaming pipeline_0.start(config_0) pipeline_1.start(config_1) try:while True:frames_0 = pipeline_0.wait_for_frames()frames_1 = pipeline_1.wait_for_frames()color_frame_0 = frames_0.get_color_frame()depth_frame_0 = frames_0.get_depth_frame()color_frame_1 = frames_1.get_color_frame()depth_frame_1 = frames_1.get_depth_frame()# if not depth_frame or not color_frame:# continuecolor_image_0 = np.asanyarray(color_frame_0.get_data())depth_image_0 = np.asanyarray(depth_frame_0.get_data())color_image_1 = np.asanyarray(color_frame_1.get_data())depth_image_1 = np.asanyarray(depth_frame_1.get_data())# window = cv.namedWindow('window', cv.WINDOW_AUTOSIZE)cv.imshow('window_0', color_image_0)cv.imshow('window_1', color_image_1)cv.waitKey(1) finally:pipeline_0.stop()pipeline_1.stop()
參考文章:Which function in python wrapper can I use to operate specific camera with its serial number? #4968
總結(jié)
以上是生活随笔為你收集整理的Intel Realsense D435 如何通过摄像头序列号获取指定摄像头的帧集对?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Intel Realsense D435
- 下一篇: python opencv 打开图像时报