kalibr、imu_utils、camera_calibration工具进行相机、imu标定以及相机imu联合标定

目录

一、camera_calibration标定工具的使用

1.1、使用环境

1.2、工具安装

1.3、标定使用

二、imu_utils标定工具的使用

 2.1、使用环境

2.2、工具安装

 2.3、标定使用

三、kalibr标定工具的使用

 3.1、使用环境

3.2、工具安装

3.3、标定使用


一、camera_calibration标定工具的使用

Camera Calibration是ROS提供的一个用于单目或者双目相机标定的包,可以十分方便地使用。使用的标定板是棋盘格(Chessboard),而非AprilTag。官方网站详细信息在下面网站中。camera_calibration - ROS Wikiicon-default.png?t=N7T8https://wiki.ros.org/camera_calibration在官网上说明这个包基于OpenCV实现,原理是一样的。在官网给出了利用它标定单目相机示例。camera_calibration/Tutorials/MonocularCalibration - ROS Wikiicon-default.png?t=N7T8https://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration双目相机示例。camera_calibration/Tutorials/StereoCalibration - ROS Wikiicon-default.png?t=N7T8https://wiki.ros.org/camera_calibration/Tutorials/StereoCalibration

1.1、使用环境

本次标定使用的计算机环境为:

# Ubuntu 18.04 ROS 1 Melodic

1.2、工具安装

使用camera_calibration标定工具标定时,需要相机驱动功能包将普通USB相机的影像流转换成Topic发布出来。不同品牌的相机可在品牌官网下载驱动功能包,本文使用通用USB相机驱动功能包,相关详细信息可在官网进行查阅。usb_cam - ROS Wikiicon-default.png?t=N7T8https://wiki.ros.org/usb_cam

通用USB相机驱动功能包安装:

# 安装命令
sudo apt-get install ros-melodic-usb-cam

 驱动USB相机:

# launch文件默认地址
/opt/ros/melodic/share/usb_cam/launch/usb_cam-test.launch

# 修改相关参数(例:video_device /dev/video2)后可驱动USB相机
roslaunch usb_cam usb_cam-test.launch

 camera_calibration标定工具安装:

# 安装命令
sudo apt-get install ros-melodic-camera-calibration

 启动camera_calibration标定工具:

# size 是标定板格子的大小 5x4代表5行4列;  square 是每个格子的边长 单位是米.
rosrun camera_calibration cameracalibrator.py image:=/camera/rgb/image_color camera:=/camera/rgb --size 5x4 --square 0.0245

1.3、标定使用

使用标定板在图像前方移动变换位置,会看到图像窗口的右上角有四个参数以及进度条,等四个进度条都变成绿色的时候,点calibration进行标定;点击save按钮,终端会打印保存路径;点击commit会将结果保存在默认位置。

# 标定文件默认路径 
~/.ros/camera_info

 标定结果文件解释:

image_width: 640
image_height: 480
camera_name: rgb_A70773W05620243A
camera_matrix:
  rows: 3
  cols: 3
  data: [558.5887623341009, 0, 345.0028122792014, 0, 560.9785552268178, 241.7893758919053, 0, 0, 1]
distortion_model: plumb_bob
distortion_coefficients:
  rows: 1
  cols: 5
  data: [0.08015751442437268, -0.1327823250512246, 0.001554338754997946, 0.01162634779859426, 0]
rectification_matrix:
  rows: 3
  cols: 3
  data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
projection_matrix:
  rows: 3
  cols: 4
  data: [563.5552368164062, 0, 351.8412745827845, 0, 0, 573.044677734375, 242.5099694345918, 0, 0, 0, 1, 0]

# 相机内参矩阵表示含义 
# camera_matrix:[fx, 0, cx, 0, fy, cy, 0, 0, 1]
 
# distorition_coefficients:[k1, k2, p1, p2, k3]
 

二、imu_utils标定工具的使用

imu_utils是用于求取IMU随机误差的开源工具。

 2.1、使用环境

本次标定使用的计算机环境为:

# Ubuntu 18.04 ROS 1 Melodic

imu型号为: yahboom CMP10A

2.2、工具安装

依赖项安装:

sudo apt-get install libdw-dev

# 安装串口驱动程序
sudo apt install ros-melodic-serial

# 查找对应的串口标号
ll /dev/ttyUSB*

安装imu_utils工具:

# imu_utils下载地址为:https://github.com/gaowenliang/imu_utils
# code_utils下载地址为:https://github.com/gaowenliang/code_utils

# 注意:
# 1、全局安装ceres库,code_imu依赖ceres;
# 2、不要同时把imu_utils和code_utils一起放到src下进行编译。由于imu_utils依赖code_utils,所以先把code_utils放在工作空间的src下面,进行编译。然后再将imu_utils放到src下面,再编译。

# 编译指令
mkdir -p imu_utils_ws/src
cd imu_utils_ws/src
catkin_init_make
cd ..
catkin_make

 出错注意事项:

# code_utils编译问题

# sumpixel_test.cpp文件
# 修改#include "backward.hpp"为 #include “code_utils/backward.hpp”

# 更多问题参考博客:https://blog.csdn.net/qq_39607707/article/details/125061020

 2.3、标定使用

配置launch文件

# imu_utils工具的launch文件位置

<!--路径: imu_utils_ws/src/imu_utils-master/launch/yahboom.laucnh -->
<!--文件名: yahboom.laucnh -->
<launch>
    <node pkg="imu_utils" type="imu_an" name="imu_an" output="screen">
        <param name="imu_topic" type="string" value= "/imu/data"/>  <!-- 话题名称 -->
        <param name="imu_name" type="string" value= "yahboom"/>  <!-- imu名称 -->
        <param name="data_save_path" type="string" value= "$(find imu_utils)/data/yahboom/"/>  <!-- 标定结果文件保存位置 -->
        <param name="max_time_min" type="int" value= "140"/>
        <param name="max_cluster" type="int" value= "100"/>
    </node>
</launch>

录制imu数据包:

# 驱动imu传感器 yahboom CMP10A
roslaunch wit_ros_imu rviz_and_imu.launch

# 录制imu数据信息 录制2.5小时
rosbag record -o imu.bag /imu/data --duration=2.5h 

 对imu进行标定:

# 运行imu_utils标定程序
roslaunch imu_utils yahboom.launch

# 播放录制好的数据包 以200倍速度播放
rosbag play -r 200 imu.bag

标定结果:

# 产生结果文件的路径在launch文件中设定 $(find imu_utils)/data/yahboom/

# yahboom_imu_param.yanl
%YAML:1.0
---
type: IMU
name: yahboom
Gyr:
   unit: " rad/s"
   avg-axis:
      gyr_n: 1.3185049024373589e-05   # 陀螺仪误差模型的高斯白噪声
      gyr_w: 1.1302794190713415e-07   # 陀螺仪bias
   x-axis:
      gyr_n: 1.9304615705852371e-05
      gyr_w: 1.5987745115722577e-07
   y-axis:
      gyr_n: 2.0250531367268400e-05
      gyr_w: 1.7920637456417667e-07
   z-axis:
      gyr_n: 0.
      gyr_w: 0.
Acc:
   unit: " m/s^2"
   avg-axis:
      acc_n: 5.9540692177708354e-03   # 加速度计误差模型的高斯白噪声
      acc_w: 3.4397387675757612e-04   # 加速度计bias
   x-axis:
      acc_n: 4.0565772029261269e-03
      acc_w: 1.9929365981837742e-04
   y-axis:
      acc_n: 3.9293939995785794e-03
      acc_w: 2.7882669771002114e-04
   z-axis:
      acc_n: 9.8762364508078026e-03
      acc_w: 5.5380127274432987e-04

 IMU内参数据结果在上述yaml文件中。

  • 三、kalibr标定工具的使用

  •  3.1、使用环境

  • # 环境
    # Ubuntu 16.04 ROS 1 Kinetic (uses OpenCV 3.3)
    # Ubuntu 18.04 ROS 1 Melodic (uses OpenCV 3.2)
    # Ubuntu 20.04 ROS 1 Noetic (uses OpenCV 4.2)
    

    3.2、工具安装

  • # 安装依赖
    sudo apt-get install -y git wget autoconf automake nano libeigen3-dev libboost-all-dev libsuitesparse-dev  doxygen libopencv-dev libpoco-dev libtbb-dev libblas-dev liblapack-dev libv4l-dev
    
    # Ubuntu 16.04
    sudo apt-get install -y python2.7-dev python-pip python-scipy \
        python-matplotlib ipython python-wxgtk3.0 python-tk python-igraph python-pyx
    # Ubuntu 18.04
    sudo apt-get install -y python3-dev python-pip python-scipy \
        python-matplotlib ipython python-wxgtk4.0 python-tk python-igraph python-pyx
    # Ubuntu 20.04
    sudo apt-get install -y python3-dev python3-pip python3-scipy \
        python3-matplotlib ipython3 python3-wxgtk4.0 python3-tk python3-igraph python3-pyx
    
    # 创建工作空间
    mkdir -p ~/kalibr_workspace/src
    cd ~/kalibr_workspace
    export ROS1_DISTRO=noetic # kinetic=16.04, melodic=18.04, noetic=20.04
    source /opt/ros/$ROS1_DISTRO/setup.bash
    catkin init
    catkin config --extend /opt/ros/$ROS1_DISTRO
    catkin config --merge-devel # Necessary for catkin_tools >= 0.4.
    catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release
    
    cd ~/kalibr_workspace/src
    git clone https://github.com/ethz-asl/kalibr.git
    
    # 编译安装
    cd ~/kalibr_workspace/
    catkin build -DCMAKE_BUILD_TYPE=Release -j4
    
    # 工具使用
    source ~/kalibr_workspace/devel/setup.bash
    rosrun kalibr <command_you_want_to_run_here>
    
    # 参考kalibr工具使用指南
    https://github.com/ethz-asl/kalibr/wiki/installation
    https://blog.csdn.net/yolon3000/article/details/117708605
    

    3.3、标定使用

  • 配置标定板:
  • # 标定板
    # 标定板下载地址 https://github.com/ethz-asl/kalibr/wiki/downloads
    # 推荐使用Aprilgrid 6x6 0.8x0.8 m (A0 page)
    
    # 配置april_6x6_80x80cm.yaml
    # calibration-targets的详细信息https://github.com/ethz-asl/kalibr/wiki/calibration-targets
    target_type: 'aprilgrid' #gridtype
    tagCols: 6               #number of apriltags
    tagRows: 6               #number of apriltags
    tagSize: 0.021           #size of apriltag, edge to edge [m]
    tagSpacing: 0.3          #ratio of space between tags to tagSize
    codeOffset: 0            #code offset for the first tag in the aprilboard

    录制标定数据包:

  • # 录制2mins数据包文件
    roslaunch usb_cam usb_cam-test.launch
    roslaunch wit_ros_imu rviz_and_imu.launch
    
    rosbag record -o /home/slam/catkin_imu_calibration/cam_imu_data/cam-imu1.bag /usb_cam/image_raw /imu/data --duration=120
    

    单目相机的标定:

  • # 标定单目相机的内参信息 --bag-from-to 10 110 表示使用10s-110s数据标定相机内参
    rosrun kalibr kalibr_calibrate_cameras --target src/kalibr-master/config/april_6x6_80x80cm.yaml --bag /home/bjh/cam-imu_2024-05-15-19-08-53.bag --bag-from-to 3 100 --models pinhole-radtan --topic /usb_cam/image_raw --show-extraction
    
    # 标定结果文件
    # cam-imu_2024-05-15-19-08-53-camchain.yaml
    cam0:
      cam_overlaps: []
      camera_model: pinhole
      distortion_coeffs: [0.017777872247314898, -0.02684631957086134, -0.001894330604890975, 0.0012601548760557617]
      distortion_model: radtan
      intrinsics: [414.10646722263186, 414.9798322310292, 333.8803601000024, 273.22676780081156]
      resolution: [640, 480]
      rostopic: /usb_cam/image_raw

    单目相机与imu的配置文件:

  • # 相机配置文件
    # camchain.yaml
    cam0:
      camera_model: pinhole
      intrinsics: [414.106, 414.979, 333.880, 273.226] # fx、fy、cx、cy
      distortion_model: radtan
      distortion_coeffs: [0.01777787, -0.02684631, -0.00189433, 0.00126015] #k1、k2、p1、p2
      rostopic: /usb_cam/image_raw
      resolution: [640, 480]
    
    # imu配置文件
    # imu.yaml
    #Accelerometers
    accelerometer_noise_density: 5.95e-03   #Noise density (continuous-time)
    accelerometer_random_walk:   3.43e-04   #Bias random walk
    
    #Gyroscopes
    gyroscope_noise_density:     1.31e-05   #Noise density (continuous-time)
    gyroscope_random_walk:       1.13e-07   #Bias random walk
    
    rostopic:                    /imu/data  #the IMU ROS topic
    update_rate:                 200.0      #Hz (for discretization of the values above)
    

    相机与imu的联合标定:

  • # 启动联合标定
    rosrun kalibr kalibr_calibrate_imu_camera --target src/kalibr-master/config/april_6x6_80x80cm.yaml --cam src/kalibr-master/config/camchain.yaml --imu src/kalibr-master/config/imu.yaml --bag cam_imu_data/cam-imu1_2024-05-15-20-48-53.bag --bag-from-to 10 110 --show-extraction
    

    标定结果:

  • # 结果保存位置 默认保存在bag目录下
    # cam-imu1_2024-05-15-20-48-53-report-imucam.pdf 标定结果pdf报告
    # cam-imu1_2024-05-15-20-48-53-results-imucam.txt 相对位姿标定结果
    
    # cam-imu1_2024-05-15-20-48-53-results-imucam.txt
    Calibration results
    ===================
    Normalized Residuals
    ----------------------------
    Reprojection error (cam0):     mean 0.60843950657, median 0.524293412496, std: 0.404512347602
    Gyroscope error (imu0):        mean 85.6904360986, median 63.0215751609, std: 75.7223230243
    Accelerometer error (imu0):    mean 1.03969304005, median 0.955396798385, std: 0.590280347338
    
    Residuals
    ----------------------------
    Reprojection error (cam0) [px]:     mean 0.60843950657, median 0.524293412496, std: 0.404512347602
    Gyroscope error (imu0) [rad/s]:     mean 0.0158751795734, median 0.0116755015872, std: 0.0140284672416
    Accelerometer error (imu0) [m/s^2]: mean 0.0874857058781, median 0.0803925390286, std: 0.0496695571321
    
    Transformation (cam0):
    -----------------------
    T_ci:  (imu0 to cam0): 
    [[-0.02627497 -0.99953152  0.01569585  0.01310044]
     [-0.08083579 -0.01352543 -0.99663566 -0.02879988]
     [ 0.99638105 -0.02745536 -0.08044254 -0.04538489]
     [ 0.          0.          0.          1.        ]]
    
    T_ic:  (cam0 to imu0): 
    [[-0.02627497 -0.08083579  0.99638105  0.0432368 ]
     [-0.99953152 -0.01352543 -0.02745536  0.01145872]
     [ 0.01569585 -0.99663566 -0.08044254 -0.03255949]
     [ 0.          0.          0.          1.        ]]
    
    timeshift cam0 to imu0: [s] (t_imu = t_cam + shift)
    0.00407106619139
    
    
    Gravity vector in target coords: [m/s^2]
    [-0.04347258 -9.8048329  -0.1782832 ]
    
    
    Calibration configuration
    =========================
    
    cam0
    -----
      Camera model: pinhole
      Focal length: [414.106, 414.979]
      Principal point: [333.88, 273.226]
      Distortion model: radtan
      Distortion coefficients: [0.01777787, -0.02684631, -0.00189433, 0.00126015]
      Type: aprilgrid
      Tags: 
        Rows: 6
        Cols: 6
        Size: 0.021 [m]
        Spacing 0.0063 [m]
    
    
    
    IMU configuration
    =================
    
    IMU0:
     ----------------------------
      Model: calibrated
      Update rate: 200.0
      Accelerometer:
        Noise density: 0.00595 
        Noise density (discrete): 0.0841457069612 
        Random walk: 0.000343
      Gyroscope:
        Noise density: 1.31e-05
        Noise density (discrete): 0.000185261976671 
        Random walk: 1.13e-07
      T_ib (imu0 to imu0)
        [[ 1.  0.  0.  0.]
         [ 0.  1.  0.  0.]
         [ 0.  0.  1.  0.]
         [ 0.  0.  0.  1.]]
      time offset with respect to IMU0: 0.0 [s]

    标定注意事项:

  • # 联合标定时报错 : RuntimeError: Optimization failed!
    
    # 解决办法:
    # 请打开kalibr/aslam_offline_calibration/kalibr/python/kalibr_calibrate_imu_camera.py文件,搜索timeOffsetPadding我的大概在198行。我先是输出它的值看了一下是0.03,然后增大此变量的值即可,我增大到了0.3 (PS:不能太大,我一开始改成了100,直接内存给干爆了)。
    
        print "Building the problem"
        #print(parsed.timeoffset_padding)    #输出看一眼timeOffsetPadding的值
        iCal.buildProblem(splineOrder=6, 
                          poseKnotsPerSecond=100, 
                          biasKnotsPerSecond=50, 
                          doPoseMotionError=False,
                          doBiasMotionError=True,
                          blakeZisserCam=-1,
                          huberAccel=-1,
                          huberGyro=-1,
                          noTimeCalibration=parsed.no_time,
                          noChainExtrinsics=(not parsed.recompute_chain_extrinsics),
                          maxIterations=parsed.max_iter,
                          # timeOffsetPadding=parsed.timeoffset_padding,     #原来的代码
                          timeOffsetPadding=0.3,     #修改后
                          verbose = parsed.verbose)
    
    # 参考:https://blog.csdn.net/qq_38337524/article/details/115589796
    

    参考博客:

  • https://blog.csdn.net/qq_39607707/article/details/125061020

  • https://blog.csdn.net/yolon3000/article/details/117708605

  • https://blog.csdn.net/qq_38337524/article/details/115589796

  • https://blog.csdn.net/LNSTOP/article/details/126556061

  • 19
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值