realsense相机内参获取

本文介绍了如何使用IntelRealSenseSDK的rs-sensor-control工具管理和操作D435摄像头,包括设备检测、传感器选择以及通过Python脚本获取内参信息,如色彩和深度流的设置和内参矩阵计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

软件方法:rs-sensor-control获取

打开 C:\Program Files (x86)\Intel RealSense SDK 2.0\tools

$ ./rs-sensor-control
======================================================

Found the following devices:

  0 : Intel RealSense D435 #817612070563

Select a device by index: 0

Device information:
  Name                 : Intel RealSense D435
  Serial Number        : 817612070563
  Firmware Version     : 05.10.06.00
  Recommended Firmware Version : 05.10.03.00
  Physical Port        : /sys/devices/pci0000:00/0000:00:14.0/usb2/2-8/2-8:1.0/video4linux/video0
  Debug Op Code        : 15
  Advanced Mode        : YES
  Product Id           : 0B07
  Camera Locked        : N/A
  Usb Type Descriptor  : 3.2

======================================================

Device consists of 2 sensors:

  0 : Stereo Module
  1 : RGB Camera

Select a sensor by index: 1

======================================================

What would you like to do with the sensor?

0 : Control sensor's options
1 : Control sensor's streams
2 : Show stream intrinsics
3 : Display extrinsics

Select an action:

注意第二项,这个就是内参的内容了。选择 2

======================================================

Sensor consists of 1 streams:
  - Color #0
Sensor provides the following stream profiles:
0  : Color #0 (Video Stream: RGB8 1920x1080@ 30Hz)
1  : Color #0 (Video Stream: RAW16 1920x1080@ 30Hz)
2  : Color #0 (Video Stream: Y16 1920x1080@ 30Hz)
3  : Color #0 (Video Stream: BGRA8 1920x1080@ 30Hz)
4  : Color #0 (Video Stream: RGBA8 1920x1080@ 30Hz)
5  : Color #0 (Video Stream: BGR8 1920x1080@ 30Hz)
6  : Color #0 (Video Stream: YUYV 1920x1080@ 30Hz)
... ...

Please select the desired streaming profile:

所有流都在这里了,比如,选择 0

Please select the desired streaming profile: 0

Principal Point         : 966.617, 532.934
Focal Length            : 1395.12, 1395.28
Distortion Model        : Brown Conrady
Distortion Coefficients : [0,0,0,0,0]

相机的内参矩阵是

K = fx      s       x0
      0     fy      y0
      0     0       1

fx,fy 为焦距,一般情况下,二者相等。
x0,y0 为主坐标(相对于成像平面)。
s 为坐标轴倾斜参数,理想情况下为 0。

python pipeline

import pyrealsense2 as rs

pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
pipeline.start(config)

time.sleep(1)
frames = pipeline.wait_for_frames()
# time.sleep(3)
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()

    # Convert images to numpy arrays
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())

# # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
# depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
#
# # Stack both images horizontally
# images = np.hstack((color_image, depth_colormap))
#
# # Show images
# cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
# cv2.imshow('RealSense', images)
# cv2.waitKey(1)

fig, axes = plt.subplots(1, 2)
for ax, im in zip(axes, [color_image, depth_image]):
    ax.imshow(im)
    ax.axis('off')
plt.show()
pipeline.stop()
import pyrealsense2 as rs
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
cfg = pipeline.start(config)
time.sleep(1)
profile = cfg.get_stream(rs.stream.depth)
intr = profile.as_video_stream_profile().get_intrinsics()
print(intr)  # 获取内参 width: 640, height: 480, ppx: 319.115, ppy: 234.382, fx: 597.267, fy: 597.267, model: Brown Conrady, coeffs: [0, 0, 0, 0, 0]
319.1151428222656
print(intr.ppx)  # 获取指定某个内参

注意:通过 python script 获取内参一定要看好自己到底用了哪个 video stream,每个 video stream 的内参都是不一样的

### Realsense Viewer 内参配置方法 Realsense Viewer 是 Intel 提供的一款用于调试和配置 RealSense 摄像头的应用程序。通过该工具,用户可以实时调整摄像头的各项参数并观察效果。以下是关于 Realsense Viewer 的内参配置及相关参数设置的方法。 #### 1. **内参的概念** 内参是指摄像机内部的几何属性,通常包括焦距、主点偏移以及镜头畸变系数等。对于 RealSense D4xx 系列设备而言,这些参数可以通过 ROS 或者官方 API 来获取或修改[^1]。 #### 2. **使用 Realsense Viewer 查看内参** 在 Realsense Viewer 中,可以直接查看当前连接设备的内参信息: - 打开 Realsense Viewer 后,选择目标设备。 - 切换到“Device Information”选项卡,这里会显示设备的基本信息,包括分辨率、帧率等。 - 转至“Advanced Mode”,点击右上角的齿轮图标进入高级模式。在这里可以选择不同的流(Stream),例如 Depth Stream 和 Color Stream,并查看对应的内参数据。 #### 3. **ROS Launch 文件中的内参配置** 如果需要通过 ROS 配置 RealSense 设备的内参,可以在 launch 文件中指定相关参数。例如: ```xml <node pkg="realsense2_camera" type="realsense2_camera_node" name="camera"> <!-- 设置深度模块的发射器 --> <arg name="emitter_enable" default="true"/> <rosparam> /camera/stereo_module/emitter_enabled: true </rosparam> <!-- 设置相机的校准参数 --> <param name="intrinsics_width" value="640"/> <param name="intrinsics_height" value="480"/> </node> ``` 上述代码片段展示了如何启用结构光发射器以及设定图像尺寸[^3]。 #### 4. **SDK 层面的内参访问** 通过 RealSense SDK (librealsense),开发者也可以编程方式读取或更改内参。以下是一个简单的 Python 示例来展示如何获取内参: ```python import pyrealsense2 as rs pipeline = rs.pipeline() config = rs.config() # 开启管道 profile = pipeline.start(config) try: # 获取活动配置文件的第一个传感器 depth_sensor = profile.get_device().first_depth_sensor() # 查询内参 intrinsics = depth_sensor.get_intrinsics() print(f"Intrinsics: {intrinsics.width}x{intrinsics.height}, fx={intrinsics.fx}, fy={intrinsics.fy}") finally: pipeline.stop() ``` 此脚本初始化了一个 RealSense 流程,并打印出了深度传感器的内参信息[^2]。 #### 5. **解决特定问题时的注意事项** 当遇到某些特殊问题,比如陀螺仪时间戳异常时,可能还需要额外的操作步骤。例如,针对 D455 型号的时间戳错乱情况,需运行补丁脚本来修正驱动环境[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值