ROSwrapper的使用(过时)

深度与RGB图像对齐

深度图像的内参

  • 通过相机参数rostopic:/camera/depth/camera_info,类型为sensor_msgs/CameraInfo获取
    • 其中包含矩阵K和矩阵P 以D415测试结果,

深度图像数据转换为点云

  • DepthCloud rostopic: /camera/depth/image_rect_raw,类型为sensor_msgs/Image 相机参数rostopic:/camera/depth/camera_info,类型为sensor_msgs/CameraInfo
    • 数据格式(假设传入callback的数据变量名均为data): 相机参数通过data.K获取 深度数据的变换
      • 画面尺寸data.heightdata.width
      • 深度数据保存在data.data中,每个数据点使用两个byte(一个unsigned short)表示,单位为mm,转换方式为:
      for iy in range(height):
          for ix in range(width):
              idx = iy*width+ix
              z = (data.data[idx*2+1]*256+data.data[idx*2])/1000.0
              if z!=0:
              ## x, y are on the camera plane, z is the depth
              np_cloud[idx][0] = z*(ix-self.k[2])/self.k[0] #x
              np_cloud[idx][1] = z*(iy-self.k[5])/self.k[4] #y
              np_cloud[idx][2] = z
      C++下索引及数据类型转换为
      unsigned short *depth_data = (unsigned short*)&img_msg->data[0];
      z = *(depth_data + iy*width + ix) / 1000.0;
      上述方法坐标系以成像平面为基准(x,y,深度为z)或转换为以camera_depth_frame坐标系为基准(相机成像平面为y,z;深度为x)
      ## same coordinate as `/camera/depth/image_rect_raw`
      ## y (left & right), z (up & down) are on the camera plane, x is the depth
      np_cloud[idx][1] = -z*(ix-self.k[2])/self.k[0]
      np_cloud[idx][2] = -z*(iy-self.k[5])/self.k[4]
      np_cloud[idx][0] = z

同时使用多个RS

  • 需要声明camera变量,否则存在同名设备会出现无法打开的情况
  • 例如其中一个相机声明为camera:=cam_1,或作为roslaunch文件的参数
    <include file="$(find realsense2_camera)/launch/rs_camera.launch">
        <arg name="camera" default="cam_1"/>
        <arg name="serial_no" default="YOUR_RS1_SERIAL_NO_HERE"/>
    </include>
    另一个相机声明为camera:=cam_2,或使用启动参数
    <include file="$(find realsense2_camera)/launch/rs_camera.launch">
        <arg name="camera" default="cam_2"/>
        <arg name="serial_no" default="YOUR_RS2_SERIAL_NO_HERE"/>
    </include>
    • 启动后rostopic中一个相机的前缀为cam_1,如/cam_1/color/image_raw
    • TF中的前缀也将从camera变为cam_1,如camera_link将变为cam_1_link

Work with multiple cameras

Important Notice: Launching multiple T265 cameras is currently not supported. This will be addressed in a later version.

Here is an example of how to start the camera node and streaming with two cameras using the rs_multiple_devices.launch.

roslaunch realsense2_camera rs_multiple_devices.launch serial_no_camera1:=<serial number of the first camera> serial_no_camera2:=<serial number of the second camera>

The camera serial number should be provided to serial_no_camera1 and serial_no_camera2 parameters. One way to get the serial number is from the rs-enumerate-devices tool.

rs-enumerate-devices | grep Serial

Another way of obtaining the serial number is connecting the camera alone, running

roslaunch realsense2_camera rs_camera.launch

and looking for the serial number in the log printed to screen under “[INFO][…]Device Serial No:“.

Another way to use multiple cameras is running each from a different terminal. Make sure you set a different namespace for each camera using the “camera” argument:

roslaunch realsense2_camera rs_camera.launch camera:=cam_1 serial_no:=<serial number of the first camera> roslaunch realsense2_camera rs_camera.launch camera:=cam_2 serial_no:=<serial number of the second camera>

坐标系

  • RealSense共提供四个坐标系:camera_depth_framecamera_depth_optical_framecamera_color_framecamera_color_optical_frame
  • 参考:
rostopic echo /tf_static 
transforms: 
  - 
    header: 
      seq: 0
      stamp: 
        secs: 1650982582
        nsecs: 839426942
      frame_id: "camera_link"
    child_frame_id: "camera_depth_frame"
    transform: 
      translation: 
        x: 0.0
        y: -0.0
        z: -0.0
      rotation: 
        x: 0.0
        y: 0.0
        z: 0.0
        w: 1.0
  - 
    header: 
      seq: 0
      stamp: 
        secs: 1650982582
        nsecs: 839426942
      frame_id: "camera_depth_frame"
    child_frame_id: "camera_depth_optical_frame"
    transform: 
      translation: 
        x: 0.0
        y: -0.0
        z: -0.0
      rotation: 
        x: -0.5
        y: 0.4999999999999999
        z: -0.5
        w: 0.5000000000000001
  - 
    header: 
      seq: 0
      stamp: 
        secs: 1650982582
        nsecs: 839481662
      frame_id: "camera_link"
    child_frame_id: "camera_color_frame"
    transform: 
      translation: 
        x: -2.4870078050298616e-06
        y: 0.01495744101703167
        z: 4.61831696156878e-05
      rotation: 
        x: -0.0013417336158454418
        y: 0.0011693149572238326
        z: 0.005542988423258066
        w: 0.999983012676239
  - 
    header: 
      seq: 0
      stamp: 
        secs: 1650982582
        nsecs: 839481662
      frame_id: "camera_color_frame"
    child_frame_id: "camera_color_optical_frame"
    transform: 
      translation: 
        x: 0.0
        y: -0.0
        z: -0.0
      rotation: 
        x: -0.5
        y: 0.4999999999999999
        z: -0.5
        w: 0.5000000000000001
---

故障排除

安装librealsense后,使用realsense-viewer时出现Cannot access /sys/class/video4linux

  • 在BIOS中将安全选项禁用UEFI secure boot。

与librealsense的共存问题(存疑)

  • 先安装pyrealsense2再安装librealsense后测试没有出现问题
  • 若出现pyrealsense2显示No device detected. Is it plugged in?,librealsense使用rs-enumerate-devices或者realsense-viewer不显示设备
    • 可能是先安装librealsense,再安装pyrealsense2两者版本不一直,抢占设备?
    • 解决方案:使用pyrealsense2,先移除librealsense,再重新安装librealsense