!!!这要根据相机驱动来看
安装usb_cam
git clone https ://github.com/ros-drivers/usb_cam
ls /dev/video*
一般笔记本电脑自带的摄像头id为0,外接的摄像头id为1,需要修改launch文件
安装camera_calibration
git clone https://github.com/ros-perception/image_pipeline.git
其他工具ILCC、autoware.ai
ubuntu18.04
环境配置
sudo apt-get install -y python-catkin-tools python-catkin-pkg python-rosdep python-wstool ros-melodic-cv-bridge ros-melodic-image-transport
sudo apt-get install -y ros-melodic-nodelet-core ros-melodic-ddynamic-reconfigure
sudo apt-get install -y ros-melodic-velodyne-pointcloud
clone
cd ~/catkin_ws/src
git clone https://github.com/ankitdhall/lidar_camera_calibration.git
mv lidar_camera_calibration/dependencies/aruco_ros aruco_ros
mv lidar_camera_calibration/dependencies/aruco_mapping aruco_mapping
cd lidar_camera_calibration
git checkout melodic
build
cd ../..
rosdep install --from-paths src --ignore-src -r -y
catkin_make -DCATKIN_WHITELIST_PACKAGES="aruco;aruco_ros;aruco_msgs"
catkin_make -DCATKIN_WHITELIST_PACKAGES="aruco_mapping;lidar_camera_calibration"
catkin_make -DCATKIN_WHITELIST_PACKAGES=""
!!!编译失败请参考https://github.com/ankitdhall/lidar_camera_calibration/wiki/Installation-ROS-Melodic-(Ubuntu-18.04)
rosrun camera_calibration cameracalibrator.py --size 11x8 --square 0.05 image:=/usb_cam/image_raw camera:=/usb_cam
size 11x8 # 12x9的标定板,有11x8个十字交点
square 0.05 #每个正方形边长0.05m
image:=/usb_cam/image_raw #相机话题
camera:=/usb_cam #相机名称
为了达到良好的标定效果,需要在摄像机周围移动标定板,并完成以下基本需求:
(1)移动标定板到画面的最左、右,最上、下方。
(2)移动标定板到视野的最近和最远处。
(3)移动标定板使其充满整个画面。
(4)保持标定板倾斜状态并使其移动到画面的最左、右,最上、下方 。
添加launch,新建文件夹,复制.ros/camera_info/head_camera.yaml标定结果。
<param name="camera_info_url" value="package://usb_cam/camera_info/head_camera.yaml"/>
标定结果说明
image_width: 640
image_height: 480
camera_name: head_camera
camera_matrix: #相机内参,用于相机坐标系,像素坐标系,图像坐标系转换
rows: 3
cols: 3
data: [462.8546707009942, 0, 307.959903912201, 0, 462.5526211528451, 193.7798324401646, 0, 0, 1]
distortion_model: plumb_bob
distortion_coefficients:#畸变系数矩阵
rows: 1
cols: 5
data: [-0.008899887143311561, -0.002703056544886668, 0.0003267615079164638, -0.0006366432387433715, 0]
rectification_matrix:#矫正矩阵,一般为单位阵
rows: 3
cols: 3
data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
projection_matrix:#外部世界坐标到像平面的投影矩阵
rows: 3
cols: 4
data: [460.4976196289062, 0, 307.3926549440584, 0, 0, 461.2594299316406, 193.6456363666366, 0, 0, 0, 1, 0]
lidar_camera_calibration
文件配置(标定板最下端距离地面110,激光雷达距离标定板90)
1./home/troy/catkin_ws/src/aruco_mapping/data/geniusF100.ini(相机内参)
# oST version 5.0 parameters
[image]
width
640
height
480
[narrow_stereo]
camera matrix
465.370017 0.000000 308.583552 x轴归一化焦距fx,***,图像中心u0
0.000000 467.389944 201.412843 ***,y轴归一化焦距fy,图像中心v0
0.000000 0.000000 1.000000***,***,***
distortion
0.007965 -0.020742 0.000045 0.001145 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
465.002472 0.000000 309.220473 0.000000
0.000000 467.747284 201.326774 0.000000
0.000000 0.000000 1.000000 0.000000
2./home/troy/catkin_ws/src/lidar_camera_calibration/conf/config_file.txt(选取点云范围,设置相机)
640 480 #相机长宽
-2.5 2.5
-2.0 2.0
0.0 1.2
0.0003 #反射强度
2
0
456.370 0.0 308.583 0.0
0.0 467.389 201.412 0.0
0.0 0.0 1.0 0.0
100
1.57 -1.57 0.0
0 0 0
0
3./home/troy/catkin_ws/src/lidar_camera_calibration/conf/marker_coordinates.txt(标定板参数)
2 #标定板数量
15.0
15.0
1.0
1.0
10.0
15.0
15.0
1.0
1.0
10.0
4.lidar_camera_calibration.yaml
修改话题
5./home/troy/catkin_ws/src/lidar_camera_calibration/launch/find_transform.launch
<?xml version="1.0"?>
<launch>
<!-- <param name="/use_sim_time" value="true"/> -->
<!-- ArUco mapping -->
<node pkg="aruco_mapping" type="aruco_mapping" name="aruco_mapping" output="screen">
<remap from="/image_raw" to="/usb_cam/image_raw"/>
<param name="calibration_file" type="string" value="$(find aruco_mapping)/data/geniusF100.ini" />
<param name="num_of_markers" type="int" value="2" />
<param name="marker_size" type="double" value="0.1"/>
<param name="space_type" type="string" value="plane" />
<param name="roi_allowed" type="bool" value="false" />
</node> -->
<rosparam command="load" file="$(find lidar_camera_calibration)/conf/lidar_camera_calibration.yaml" />
<node pkg="lidar_camera_calibration" type="find_transform" name="find_transform" output="screen">
</node>
</launch>
运行传感器驱动和标定文件
roslaunch usb_cam-test.launch
roslaunch velodyne_pointcloud VLP16_points.launch
roslaunch lidar_camera_calibration find_transform.launch
!!!点云图要清楚看到两个正方形
https://www.bilibili.com/video/BV1u4411W7hp?from=search&seid=17969155147339204978
#选择标定板的边
添加链接描述实际上:激光雷达在相机的右1cm后7cm上5cm
参考文章
相机标定原理
涉及坐标系:世界坐标系、相机坐标系、图像坐标系和像素坐标系
注:图像坐标系单位mm
本文相机分辨率640*480,焦距1.8mm,相机尺寸36x36mm
则u0=640/2=320,v0=480/2=240,dx=0.00375,dy=0.00375#像素元大小,感光板/分辨率
fx=f/dx=480,fy=f/dy=480
camera matrix #相机内参,用于相机坐标系,像素坐标系,图像坐标系转换
465.370017 0.000000 308.583552 #x轴归一化焦距fx,***,图像中心u0
0.000000 467.389944 201.412843 #***,y轴归一化焦距fy,图像中心v0
0.000000 0.000000 1.000000 #***,***,***
标定原理
要将点云投影到图片上,需要知道激光雷达与相机之间的位置转换矩阵以及相机内参。
这里涉及的坐标转换流程是:激光雷达坐标系—》摄像头坐标系—》图像平面坐标系。中间过程相应的就涉及到两个转换矩阵。
原理
1.aruco_mapping图像中找到aruco marker,并发布6DOF的位姿
2.在cloud中手动标记line-segments,标记完8条直线段之后,就得到了最终的变换矩阵,中间值存储在conf/points.t。
points.txt文件
-0.121706 -0.190662 0.948146
0.00291819 -0.0673494 0.921416
-0.102619 0.0307781 0.91676
-0.218277 -0.0498588 0.929411#marker1四个角点,雷达为原点,单位m
0.130236 -0.192367 1.00758
0.251231 -0.0913554 0.982314
0.159098 0.0447276 0.998673
0.0308117 -0.072765 0.952486#marker2四个角点,雷达为原点,单位m
-0.100045 -0.169544 0.879531
0.0142628 -0.0724326 0.881297
-0.081828 0.041033 0.861495
-0.196135 -0.0560789 0.859729#marker1四个角点,相机为原点,单位m
0.160968 -0.178079 0.921558
0.274381 -0.0804665 0.932017
0.178164 0.0332287 0.914247
0.0647513 -0.0643837 0.903789#marker2四个角点,相机为原点,单位m
设置迭代100次,通过对100次迭代生成的平移矩阵求平均,即可得到最终的平移矩阵,通过对100个旋转矩阵转换成四元数,然后求平均,即可得到最终的旋转矩阵,从而得到最终的标定矩阵。