当前位置:   article > 正文

【学习总结】cam_lidar_calibration:激光雷达与相机联合标定_optimising the selection of samples for robust lid

optimising the selection of samples for robust lidar camera calibration

由于深度学习需要自己构造数据集,对于雷达和相机等多传感器融合数据,传感器标定是不可避免的,在前段时间学习了激光雷达和相机的联合标定,在此记录一下

源码链接:GitHub - acfr/cam_lidar_calibration: (ITSC 2021) Optimising the selection of samples for robust lidar camera calibration. This package estimates the calibration parameters from camera to lidar frame.(ITSC 2021) Optimising the selection of samples for robust lidar camera calibration. This package estimates the calibration parameters from camera to lidar frame. - GitHub - acfr/cam_lidar_calibration: (ITSC 2021) Optimising the selection of samples for robust lidar camera calibration. This package estimates the calibration parameters from camera to lidar frame.https://github.com/acfr/cam_lidar_calibration如果github无法访问,可是尝试镜像站:

GitHub - acfr/cam_lidar_calibration: (ITSC 2021) Optimising the selection of samples for robust lidar camera calibration. This package estimates the calibration parameters from camera to lidar frame.(ITSC 2021) Optimising the selection of samples for robust lidar camera calibration. This package estimates the calibration parameters from camera to lidar frame. - GitHub - acfr/cam_lidar_calibration: (ITSC 2021) Optimising the selection of samples for robust lidar camera calibration. This package estimates the calibration parameters from camera to lidar frame.https://hub.nuaa.cf/acfr/cam_lidar_calibration论文链接:https://arxiv.org/abs/2103.12287

1.环境配置

系统:ubunutu20.04

ros -noetic

激光雷达: VLP-16

相机:海康威视

1.1 构建工作空间并复制源码

考虑到可能github访问不方便,下面涉及到github网址的部分均使用镜像站hub.nuaa.cf代替,如果需要官网源码,将涉及到镜像网址的部分均替换成github网址即可。

  1. # 创建工作空间
  2. (base) hzt@hzt-ubuntu20:~$ mkdir -p calib_ws/src &&cd calib_ws
  3. (base) hzt@hzt-ubuntu20:~/calib_ws$ cd src
  4. (base) hzt@hzt-ubuntu20:~/calib_ws/src$ catkin_init_workspace
  5. # 克隆仓库
  6. (base) hzt@hzt-ubuntu20:~/calib_ws/src$ git clone https://hub.nuaa.cf/acfr/cam_lidar_calibration
  7. # 编译
  8. (base) hzt@hzt-ubuntu20:~/calib_ws/src$ cd ..
  9. (base) hzt@hzt-ubuntu20:~/calib_ws$ catkin_make

1.2 部分编译报错

        1.2.1

  1. #编译时报错
  2. (base) hzt@hzt-ubuntu20:~/calib_ws$ catkin_make
  3. Base path: /home/hzt/calib_ws
  4. Source space: /home/hzt/calib_ws/src
  5. Build space: /home/hzt/calib_ws/build
  6. Devel space: /home/hzt/calib_ws/devel
  7. Install space: /home/hzt/calib_ws/install
  8. ####
  9. #### Running command: "cmake /home/hzt/calib_ws/src -DCATKIN_DEVEL_PREFIX=/home/hzt/calib_ws/devel -DCMAKE_INSTALL_PREFIX=/home/hzt/calib_ws/install -G Unix Makefiles" in "/home/hzt/calib_ws/build"
  10. ####
  11. -- The C compiler identification is GNU 9.4.0
  12. -- The CXX compiler identification is GNU 9.4.0
  13. -- Check for working C compiler: /usr/bin/cc
  14. -- Check for working C compiler: /usr/bin/cc -- works
  15. -- Detecting C compiler ABI info
  16. -- Detecting C compiler ABI info - done
  17. -- Detecting C compile features
  18. -- Detecting C compile features - done
  19. -- Check for working CXX compiler: /usr/bin/c++
  20. -- Check for working CXX compiler: /usr/bin/c++ -- works
  21. -- Detecting CXX compiler ABI info
  22. -- Detecting CXX compiler ABI info - done
  23. -- Detecting CXX compile features
  24. -- Detecting CXX compile features - done
  25. -- Using CATKIN_DEVEL_PREFIX: /home/hzt/calib_ws/devel
  26. -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic
  27. -- This workspace overlays: /opt/ros/noetic
  28. -- Found PythonInterp: /home/hzt/anaconda3/bin/python3 (found suitable version "3.10.9", minimum required is "3")
  29. -- Using PYTHON_EXECUTABLE: /home/hzt/anaconda3/bin/python3
  30. -- Using Debian Python package layout
  31. -- Could NOT find PY_em (missing: PY_EM)
  32. CMake Error at /opt/ros/noetic/share/catkin/cmake/empy.cmake:30 (message):
  33. Unable to find either executable 'empy' or Python module 'em'... try
  34. installing the package 'python3-empy'
  35. Call Stack (most recent call first):
  36. /opt/ros/noetic/share/catkin/cmake/all.cmake:164 (include)
  37. /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include)
  38. CMakeLists.txt:58 (find_package)
  39. -- Configuring incomplete, errors occurred!
  40. See also "/home/hzt/calib_ws/build/CMakeFiles/CMakeOutput.log".
  41. Invoking "cmake" failed

解决方法:

# 如果出现上述报错,这是因为环境中存在多个python环境,所以在编译的时候声明所使用的python(根本原因是anaconda

(base) hzt@hzt-ubuntu20:~/calib_ws$ catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3
1.2.2
  1. /home/hzt/calib_ws/src/cam_lidar_calibration/include/cam_lidar_calibration/optimiser.h:10:10: fatal error: opencv/cv.hpp: 没有那个文件或目录
  2. 10 | #include <opencv/cv.hpp>
  3. | ^~~~~~~~~~~~~~~
  4. compilation terminated.

根据报错提示找到对应代码处,更改导入头文件

#include <opencv2/opencv.hpp>

1.2.3

  1. /home/hzt/calib_ws/src/cam_lidar_calibration/src/optimiser.cpp:427:48: error: ‘CV_REDUCE_SUM’ was not declared in this scope
  2. 427 | cv::reduce(trans_diff, summed_diff, 1, CV_REDUCE_SUM, CV_64F);

optimiser.h头文件中添加:

#include<opencv2/core/core_c.h>

1.2.4 anaconda 与ros自带的QT路径冲突

  1. usr/bin/ld: /home/hzt/anaconda3/lib/libQt5Core.so.5.15.2: undefined reference to `std::__exception_ptr::exception_ptr::_M_release()@CXXABI_1.3.13'
  2. /usr/bin/ld: /home/hzt/anaconda3/lib/libQt5Widgets.so.5.15.2: undefined reference to `std::__throw_bad_array_new_length()@GLIBCXX_3.4.29'
  3. /usr/bin/ld: /home/hzt/anaconda3/lib/libQt5Core.so.5.15.2: undefined reference to `std::__exception_ptr::exception_ptr::_M_addref()@CXXABI_1.3.13'
  4. collect2: error: ld returned 1 exit status

cam_lidar_calib_ws/src/cam_lidar_calibration/CMakeLists.txt里找到

find_package(Qt5 REQUIRED Core Widgets)

在这行代码前面添加Qt5config.cmake文件的路径

SET(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake")

修改完后,最好删除build和devel文件夹,重新运行编译命令。

1.3 运行示例

打开终端进入工作空间,刷新环境变量:

  1. (base) hzt@hzt-ubuntu20:~$ cd calib_ws/
  2. (base) hzt@hzt-ubuntu20:~/calib_ws$ source devel/setup.bash

运行示例标定:

roslaunch cam_lidar_calibration run_optimiser.launch import_samples:=true

终端可以看到对50个样本位姿进行计算VOQ得分,结果保存在src/cam_lidar_calibration/data/vlp

显示标定结果:

roslaunch cam_lidar_calibration assess_results.launch csv:="$(rospack find cam_lidar_calibration)/data/vlp/calibration_quickstart.csv" visualise:=true

可以看到显示结果:

至此,源码的下载与环境安装结束。

2.实际标定

在进行实际标定之前,首先先检查雷达和相机的topic,这套代码需要激光雷达的点云具有XYZIR的点云topic、相机图像topic,和发布相机内参的topic(即camera_info)。

2.1 准备标定板

代码的readme里已经给了标定板的下载地址,自己准备的标定板也可以,标定板采用棋盘格就可以,尽量大一点。

 2.2 准备rosbag

运行自己的激光雷达和相机,确认发布的topic包含了激光雷达点云、相机图像、camrea_info。

当相机可以发布camrea_info时,打开rviz,调整标定板的距离(对于vlp-16线雷达,我自己的实际经验是保持在2米左右),标定板如图所示成45度,让雷达尽可能多的线打在标定板上,保持静止不动,录制包含上述话题的bag(我录制的七八秒钟即可):

 更改棋盘格的位姿(距离、高度、俯仰、左右移动),每次更改之后就保持静止,一共录制九个左右(也可以更多)。

当相机不发布camrea_info时,需要自己手动发布,先看看它主要包含什么内容。通过打印该话题内容可以看到主要是header、矩阵D、K、R、P,其中D是相机畸变系数、K为相机内参、R为旋转矩阵,可以直接设置为单位阵,P为校正后的投影矩阵。

 了解了camrea_info的内容之后,就可以自己手动发布了,在cam_lidar_calib_ws/src/cam_lidar_calibration/src/目录下新建cam_info.cpp文件,其代码如下:

  1. #include <ros/ros.h>
  2. #include <iostream>
  3. #include <opencv2/opencv.hpp>
  4. #include <sensor_msgs/CameraInfo.h>
  5. #include <math.h>
  6. using namespace std;
  7. using namespace cv;
  8. sensor_msgs::CameraInfo getCameraInfo(void){ // extract cameraInfo.
  9. sensor_msgs::CameraInfo cam;
  10. vector<double> D{-1.2634357e-01, 1.7202073e-01, 0.000000, 0.000000, 0.000000};
  11. boost::array<double, 9UL> K = {
  12. 1.0690539e+03 , 0.0000000e+00, 6.3718590e+02 ,
  13. 0.0000000e+00 , 1.0688654e+03 , 4.8939118e+02,
  14. 0.0000000e+00 , 0.0000000e+00 , 1.0000000e+00
  15. };
  16. boost::array<double, 12UL> P = {
  17. 1.0690539e+03 , 0.0000000e+00, 6.3718590e+02 ,0.0000000e+00,
  18. 0.0000000e+00 , 1.0688654e+03 , 4.8939118e+02,0.0000000e+00,
  19. 0.0000000e+00 , 0.0000000e+00 , 1.0000000e+00,0.0000000e+00
  20. };
  21. boost::array<double, 9> r = {1, 0, 0, 0, 1, 0, 0, 0, 1};
  22. cam.height = 1200;
  23. cam.width = 1920;
  24. cam.distortion_model = "plumb_bob";
  25. cam.D = D;
  26. cam.K = K;
  27. cam.P = P;
  28. cam.R = r;
  29. cam.binning_x = 0;
  30. cam.binning_y = 0;
  31. cam.header.frame_id = "camera"; //frame_id为camera,也就是相机名字
  32. cam.header.stamp = ros::Time::now();
  33. cam.header.stamp.nsec = 0;
  34. return cam;
  35. }
  36. int main(int argc, char** argv) {
  37. ros::init(argc, argv, "camera_info"); //初始化了一个节点,名字为camera_info
  38. ros::NodeHandle n;
  39. ros::Publisher pub = n.advertise<sensor_msgs::CameraInfo>("/camera/camera_info", 1000);
  40. sensor_msgs::CameraInfo camera_info_dyn;
  41. ros::Rate rate(1); //点云更新频率0.5Hz
  42. while (ros::ok())
  43. {
  44. camera_info_dyn = getCameraInfo();
  45. pub.publish(camera_info_dyn); //发布出去
  46. rate.sleep();
  47. }
  48. ros::spin();
  49. return 0;
  50. }

在CMakeLists.txt里添加可执行权限:

  1. add_executable(cam_info src/cam_info.cpp)
  2. target_link_libraries(cam_info
  3. ${catkin_LIBRARIES}
  4. ${OpenCV_LIBS}

重新编译,运行该代码

(base) hzt@hzt-ubuntu20:~/cam_lidar_calib_ws$ rosrun cam_lidar_calibration cam_info

 可以打印出来对比info信息。

2.3 开始标定

打开src/cam_lidar_calibration/cfg/params.yaml,修改参数,主要更改topic名称,以及棋盘格参数。

 打开终端,启动标定程序

hzt@hzt-ubuntu20:~/cam_lidar_calib_ws$ roslaunch cam_lidar_calibration run_optimiser.launch import_samples:=false

(可选)仅对于相机不发布camrea_info,启动手动发布camrea_info节点

(base) hzt@hzt-ubuntu20:~/cam_lidar_calib_ws$ rosrun cam_lidar_calibration cam_info

播放录制好的bag,(0701.bag 更改为你自己bag的名字)

rosbag play 0701.bag -r 0.1

 此时可能打开的rviz图像和雷达点云都看不见,别急,可能是rviz的topic设置不对:

 点击Panels,勾选Displays,更改Fixed Frame为自己的点云frame,image的topic也更改为自己的话题。

通过rqt_config工具,截取xyz坐标轴,使rviz中的点云尽量只保留棋盘格区域;
 

 点击capture进行一次截取,拟合边界成功则如下所示:

重新载入下一个rosbag,调整xyz坐标轴,使rviz中的点云尽量只保留棋盘格区域,再点击capture;重复截取,包括至少3个位姿,可以更多;如果某次截取效果不好,可以discard当次截取;

数量足够后,点击optimize按钮,后台开始优化;优化结果会保存在cam_lidar_calib_ws/src/cam_lidar_calibration/data下。

 

 

2.4 检验标定效果

(py3.8) hzt@hzt-ubuntu20:~/cam_lidar_calib_ws$ roslaunch cam_lidar_calibration assess_results.launch csv:="$(rospack find cam_lidar_calibration)/data/vlp/calibration_quickstart.csv" visualise:=true

其中

csv:="$(rospack find cam_lidar_calibration)/data/vlp/calibration_quickstart.csv"

替换为你自己保存的标定结果路径。运行后终端显示标定的平均重投影误差,可以看到标定结果如下:

 至此,标定结束,终端显示标定参数:

Calibration params (roll,pitch,yaw,x,y,z): -1.5809,0.0041,-1.4960,0.0706,0.0141,-0.1139

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/312991
推荐阅读
  

闽ICP备14008679号