多传感器融合已成为自动驾驶和机器人感知领域的核心技术之一。在实际应用中,激光雷达与相机的联合标定是实现精确数据融合的关键第一步。本文将手把手带你完成Livox雷达与DJI H20T相机的标定全过程,从环境配置到最终验证,每个步骤都包含详细的操作说明和常见问题解决方案。
不同于理论讲解,本指南聚焦于实战操作,特别适合刚接触传感器标定的工程师和学生。你将学习到:
在开始前,请确保你已准备好以下硬件:
提示:标定板的质量直接影响标定精度,建议使用高精度打印的棋盘格或购买专业标定板。
首先安装基础依赖:
bash复制sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
Livox标定工具对OpenCV版本有严格要求,推荐安装3.4.10:
bash复制wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.10.zip
unzip opencv.zip
cd opencv-3.4.10
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install
标定过程需要Ceres Solver 1.14.0版本:
bash复制sudo apt-get install -y libgoogle-glog-dev libgflags-dev libatlas-base-dev libeigen3-dev libsuitesparse-dev
wget http://ceres-solver.org/ceres-solver-1.14.0.tar.gz
tar xvf ceres-solver-1.14.0.tar.gz
cd ceres-solver-1.14.0
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install
bash复制git clone https://github.com/Livox-SDK/Livox-SDK.git
cd Livox-SDK/build && cmake ..
make
sudo make install
git clone https://github.com/Livox-SDK/livox_ros_driver.git ws_livox/src
cd ws_livox
catkin_make
source devel/setup.bash
bash复制git clone https://github.com/Livox-SDK/livox_camera_lidar_calibration.git
cd livox_camera_lidar_calibration
mkdir build && cd build
cmake ..
make
cameraCalib.cpp中的图片路径bash复制./cameraCalib
常见问题解决:
imshow相关代码config.json文件:json复制{
"camera_intrinsic": "camera_intrinsic.yaml",
"image_path": "./image/",
"pcd_path": "./pcd/",
"use_rough_calib": false
}
bash复制./calibration
标定结果将保存在extrinsic.yaml中。
推荐使用Autoware 1.14版本:
bash复制sudo apt-get install -y ros-melodic-autoware-core ros-melodic-autoware-msgs
git clone https://github.com/CPFL/Autoware.git --branch 1.14.0
cd Autoware/ros/src
catkin_init_workspace
cd ../..
rosdep install -y --from-paths src --ignore-src --rosdistro melodic
./catkin_make_release
启动Autoware标定工具:
bash复制roslaunch autoware_camera_lidar_calibrator camera_lidar_calibration.launch
关键参数设置:
| 参数 | 说明 | 示例值 |
|---|---|---|
| Pattern Size | 棋盘格实际尺寸(m) | 0.025 |
| Pattern Number | 棋盘格内部角点数 | 11x8 |
| Max Iterations | 优化迭代次数 | 50 |
注意:避免在强光或反光环境下采集数据,这会影响标定精度。
使用rviz可视化标定结果:
bash复制roslaunch livox_ros_driver livox_lidar.launch
rosrun image_view image_view image:=/camera/image_raw
rviz
在rviz中添加:
验证点云是否准确投影到图像上。
将相机颜色信息映射到点云:
python复制import numpy as np
import cv2
import open3d as o3d
# 加载标定参数
R = np.loadtxt('rotation.txt')
T = np.loadtxt('translation.txt')
# 点云投影
points = np.loadtxt('pointcloud.xyz')
img = cv2.imread('image.png')
colors = []
for pt in points:
# 坐标变换
cam_pt = np.dot(R, pt) + T
# 投影到图像平面
u = int(fx * cam_pt[0]/cam_pt[2] + cx)
v = int(fy * cam_pt[1]/cam_pt[2] + cy)
if 0 <= u < img.shape[1] and 0 <= v < img.shape[0]:
colors.append(img[v,u]/255.0)
else:
colors.append([0,0,0])
# 创建彩色点云
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points)
pcd.colors = o3d.utility.Vector3dVector(colors)
o3d.visualization.draw_geometries([pcd])
可能原因:
解决方案:
常见错误:
code复制ceres-solver not found
解决方案:
bash复制sudo apt-get install libceres-dev
或者手动指定Ceres路径:
bash复制cmake -D Ceres_DIR=/usr/local/lib/cmake/Ceres ..
使用PTP协议实现硬件时间同步:
bash复制sudo apt-get install linuxptp
sudo ptp4l -i eth0 -m -S
sudo phc2sys -s eth0 -c CLOCK_REALTIME -m -O 0
创建自动化标定流程:
bash复制#!/bin/bash
# 自动采集数据
for i in {1..20}
do
rosrun image_view image_saver image:=/camera/image_raw _filename_format:="image_%04d.jpg" _save_all_image:=false &
sleep 1
killall image_saver
rosrun pcl_ros pointcloud_to_pcd input:=/livox/lidar _prefix:=pcd_ _fixed_frame:=livox_frame _binary:=true &
sleep 1
killall pointcloud_to_pcd
done
# 自动标定
python auto_calibrate.py --images image_*.jpg --pcds pcd_*.pcd
在最近的一个农业机器人项目中,我们使用Livox Mid-100和DJI H20T进行果园环境的三维重建。初期标定时遇到了点云投影偏移的问题,最终发现是相机镜头畸变校正不充分导致的。重新进行相机内参标定并应用畸变校正后,投影精度显著提高。
另一个常见问题是标定结果的稳定性。我们发现,在温度变化较大的环境中(如室外早晚温差),标定参数会出现微小漂移。解决方案是:
对于需要高精度融合的应用,建议每周进行一次标定验证,特别是在设备经过运输或剧烈震动后。