Camera calibration via charuco board ROS package.
If you want to calibrate the camera on the embedded computer (like the Raspberry Pi), you should install this package on your laptop and use remote calibration launch file.
Currently the package provides the following nodes:
charuco_calibration_node
- an interactive ChArUco calibration node that uses an image topic to get calibration images;calibrate_camera_from_files
- a non-interactive ChArUco calibration node that uses a list of files for calibration.
Create catkin workspace dir and sources dir in it (if you don't have catkin workspace):
mkdir -p ~/catkin_ws/src
Clone this repo to ~/catkin_ws/src
directory:
git clone https://github.com/CopterExpress/charuco_calibration.git
Execute catkin_make command from catkin workspace directory:
cd ~/catkin_ws
catkin_make
Add environment variables that are needed for ROS:
source devel/setup.bash
You need to execute previous command on every bash login before starting node. If you want to do it automatically add this command to /home/$USER/.bashrc
file.
Run calibration node for your computer by executing
roslaunch charuco_calibration calibration.launch
Run calibration node for remote computer on some hostname
(e.g. on Raspberry Pi) by executing
ROS_MASTER_URI="http://hostname:11311" roslaunch charuco_calibration remote_calibration.launch
Put all images that are to be used for calibration in a folder (for example, /home/user/calibration_images
). After that, run:
roslaunch charuco_calibration files_calibration.launch images_path:=/home/user/calibration_images
Do note that you need to specify the absolute path for calibration images!
The program will look for image files in the folder, select the ones that are suitable for calibration, and output a calibration.yaml
file to the images folder.
We strongly recommend using lossless image formats like
png
for source images.
squares_x
- number of charuco board squares along x axis, default is 6.squares_y
- number of charuco board squares along y axis, default is 8.square_length
- length of square side in m, default is 0.021.marker_length
- length of aruco side in m, default is 0.013.dictionary_id
- id of aruco markers dictionary, default is 4 (DICT_5X5_50). The dictionary ID is as described in OpenCV documentation (DICT_4x4_50 is 0, DICT_4x4_100 is 1, etc).aspect_ratio
- ifCALIB_FIX_ASPECT_RATIO
is set, use this aspect ratio for calibration.perform_refinement
- attempt to find additional markers based on the currently detected ones (as described in OpenCV documentation), default is false.output_file
- name of the calibration file, default iscalibration.yaml
.
Parameters in calibration_flags
namespace (see launch/calibration_params.yaml
) are flags that are passed to calibrateCameraCharuco
; their description can be found in OpenCV documentation.
Parameters in detector_parameters
namespace (see launch/calibration_params.yaml
) are used by ArUco detector and are described in their own OpenCV documentation page. They can be tweaked to improve ArUco marker detection.
draw_historical_markers
- display points where key points for the board have been detected on the preview image, default istrue
.save_images
- option to save all captured images to folder with calibration, default istrue
.
images_path
- path to the folder with images, default iscalibration_images
Note that the working directory for nodes launched from
roslaunch
is set to~/.ros
. Use absolute paths whenever possible.
charuco_calibration_node
subscribes to image
topic. Be sure to remap your actual image topic to it.
charuco_calibration_node
publishes a board
topic that contains the ChArUco board image.
calibrate_camera_from_files
does not subscribe to any topic and does not publish any topics. It exits after the calibration is done or if it cannot be performed.
You will need special charuco board, which will be generated in ~/.ros/board.png
and published to the board
topic after launching charuco_calibration_node
. Print this board, measure square and marker lengths and enter these values as square_length and marker_length parameters of charuco_calibration_node in required .launch
file. You can find directory with launch files with roscd charuco_calibration/launch
command. If you run the node first time, restart it after you correct .launch
file.
Make about 20-25 different pictures of the charuco board from different angles by pressing "c" key. Make camera calibration by pressing the "esc" key after you make enough frames. Blue calibration dots should cover the whole image during the process of calibration.
Calibration file will be saved in ~/.ros/calibration_<date>_<time>
directory as calibration.yaml
file by default. You can change the name of the calibration file in the output_file
parameter in the launch file.
Also, you can save all captured images to the calibration folder for further analysis if you specify save_images
parameter as true
.
The main goal of calibration is to get the calibration file with minimal reprojection error. Typical reprojection error is 0.3
, typical reprojection error for aruco markers is 1.0
.
You can check visual quality of calibration by viewing undistorted images from camera after the process of calibration.
Also, you can use undistortion node from clever_tools package to publish indistorted image to topic. You can view it using web_video_server or rqt_image_view ROS packages.
If you already have source images for calibration (for example, after a previous run of charuco_calibration_node
), you can run the non-interactive tool by running roslaunch charuco_calibration files_calibration.launch images_path:=/path/to/calibration_images
. The calibration file will be placed at the specified path.
Note that all images at the folder are expected to have the same dimensions.
Put the calibration file to the required directory for the program which requires it. For example, in the clever package the calibration file should be placed to the camera_info folder and the path to the calibration file should be specified in the main_camera.launch file.