获取并输出realsense d435i相机的所有镜头的内参与外参,其他realsense相机也可用
发布时间:2026/6/10 20:56:26
分类:文化教育
浏览:1234

##获取并输出realsense相机两个红外镜头infrared 1与21为左红外2为右红外的内参、rgb镜头的内参、深度镜头可理解为两个红外联合得到的深度镜头的内参、两个红外镜头间的外参、rgb镜头到两个红外镜头的外参、深度镜头到rgb镜头的外参##注意先pip install pyrealsense2; pip install opencv-python import pyrealsense2 as rs def get_camera_parameters(): # 创建一个管道对象 pipeline rs.pipeline() # 创建一个配置对象 config rs.config() # 配置管道以流式传输深度和彩色流 config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)##注意分辨率不同的分辨率对应的内外参不同 config.enable_stream(rs.stream.color, 1280, 720, rs.format.rgb8, 30)##注意分辨率不同的分辨率对应的内外参不同 config.enable_stream(rs.stream.infrared, 1, 640, 480, rs.format.y8, 30)##注意分辨率不同的分辨率对应的内外参不同 config.enable_stream(rs.stream.infrared, 2, 640, 480, rs.format.y8, 30)##注意分辨率不同的分辨率对应的内外参不同 # 开始流式传输 profile pipeline.start(config) # 获取各个流的内参 depth_profile profile.get_stream(rs.stream.depth) color_profile profile.get_stream(rs.stream.color) infrared1_profile profile.get_stream(rs.stream.infrared, 1) infrared2_profile profile.get_stream(rs.stream.infrared, 2) depth_intr depth_profile.as_video_stream_profile().get_intrinsics() color_intr color_profile.as_video_stream_profile().get_intrinsics() infrared1_intr infrared1_profile.as_video_stream_profile().get_intrinsics() infrared2_intr infrared2_profile.as_video_stream_profile().get_intrinsics() # 获取外参 extrinsics_ir1_to_ir2 infrared1_profile.get_extrinsics_to(infrared2_profile) extrinsics_color_to_ir1 color_profile.get_extrinsics_to(infrared1_profile) extrinsics_color_to_ir2 color_profile.get_extrinsics_to(infrared2_profile) extrinsics_depth_to_color depth_profile.get_extrinsics_to(color_profile) # 打印内参 print(Depth camera intrinsics:, depth_intr) print(Color camera intrinsics:, color_intr) print(Infrared 1 camera intrinsics:, infrared1_intr) print(Infrared 2 camera intrinsics:, infrared2_intr) # 打印外参 print(Extrinsics from Infrared 1 to Infrared 2:, extrinsics_ir1_to_ir2) print(Extrinsics from Color to Infrared 1:, extrinsics_color_to_ir1) print(Extrinsics from Color to Infrared 2:, extrinsics_color_to_ir2) print(Extrinsics from Depth to Color:, extrinsics_depth_to_color) # 停止流式传输 pipeline.stop() if __name__ __main__: get_camera_parameters()