##获取并输出realsense相机两个红外镜头(infrared 1与2,1为左红外,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()