This is a sample method to calibrate camera and lidar jointly. I think this method is suitable for 16, 32, 64 line-lidar. If you want to run this code successfully, please read the discription carefully.
- PolyWorks 2019.
- Matlab 2019a.
Doawload this code and perform the following steps.
- Base requirements
- All images must be undistorted. This matter is of the utmost importance.
- Calibration board requires black and white checkerboard lattice and one side is odd, one side is even.
- The short edge of the chessboard should be at the top of the image. The edges of the checkerboard cannot be parallel to the edges of the image. Pose of chessboard in image must look like second row shown below (first row is wrong pose):
- The short edge of the chessboard of pointcloud should be at the top of the z-axis direction of lidar. The edges of the checkerboard of pointcloud cannot be parallel to the z-axis of lidar.
- Data Storage
- Put your camera images (
.png
) intodata/images
and you have to name it numerically. - Put your lidar data (
.txt
) intodata/pointcloud
and each line of the file has only xyz coordinates, for example:
0.5363237262 -0.3014609218 -0.1039963961
0.5608119369 -0.3181324303 -0.1093295515
0.5810572505 -0.3322938681 -0.1137738377
0.6180613041 -0.3567755520 -0.1217735633
...
- You can use command below to covert
.pcd
file to.txt
file in linux.
$ pcl_converter -f ascii 1.pcd dst.pcd
$ cat dst.pcd | grep -v [A-Z] | grep -v [a-z] | cut -f 1,2,3 -d ' ' > 1.txt
- Fit the chessboad to square in the point cloud
-
file -> input -> pointcloud, choose .txt file
-
choose background points, press delete key to delete these points, only save chessboard points.
-
Save '.igs' file to
data/chessboard_pointcloud_igs
. Note that the prefix name must be a number and its prefix name must match the prefix name of the image indata/images
. -
Repeat the above steps until all pointcloud of chessboard are fitted.
- Configuration
- Open matlab2019 and change the matlab folder to the root directory
Camera-lidar-joint-calibration/
. - Open
joint_calibration.m
file and you need to modify the following options.
x_grids = 5; % number of grids of short edges of chessboard
y_grids = 8; % number of grids of long edges of chessboard
imageType = 'png'; % image format
% camera parameters
focalLength = [2525.9, 2528.1]; % fx, fy
principalPoint = [942.9102, 584.8342]; % cx, cy
imageSize = [1080, 1920]; % image size
- Check the result of image corner detection
- If you run this code for the first time, you should check the result of image corner detection carefully. If the corners of some images are not detected successfully, the
MinCornerMetric
parameter needs to be adjusted . So you should modify the configuration as below.
MinCornerMetric = 0.4; % Adjusting this parameter can better detect corner points
onlyShowDetection = 'true';% only show result of image corner detection
- Joint calibration
-
If corner detection is successful, you should modify the cofiguration to
onlyShowDetection = 'false'
to start calibrating jointly. -
Reprojection error will be shown in images and the cross symbol represents the reprojection point.
-
All the pointcloud will be prejected into corresponding image.
- Notes
- The projection formula from point cloud to image looks like this
Pc = K * R * (Pw - T)
- For better results, you shold use at least 20 pairs pointcloud and images. And the calibration board should cover all positions of the images as much as possible.