11.5.5. Calibration
11.5.5.1. Where to save the calibration results
With ROS1, the simplest way to save and retrieve the results of a
camera calibration is to create a dummy ROS package. The package name
will allow other ROS nodes to find the results of the camera
calibration later on. For ROS2, we suggest to use the dvrk_video source directory to save the calibration results.
Stereo
ROS1 only!
You will need to create a new package to store the calibration results. At that point, choose a name for your camera (aka stereo rig). For this example, we will use “jhu_daVinci”:
cd ~/catkin_ws/src
catkin_create_pkg jhu_daVinci
catkin build
source ~/catkin_ws/devel/setup.bash # you have a new package so you need to source again
Mono
ROS1 only!
There is no difference but for sake of demonstration, we will create the package under a different name, say “depstech”, a familiar brand of cheap USB cameras.
cd ~/catkin_ws/src
catkin_create_pkg depstech
catkin build
source ~/catkin_ws/devel/setup.bash # you have a new package so you need to source again
11.5.5.2. Start the video
Stereo
The following is based on dVRK provided launch files to capture the stereo video using DeckLink SDI frame grabbers. If your frame grabbers are different you will have to create your own launch files. Note that you have to provide the name of your stereo rig:
# ROS1
roslaunch dvrk_video decklink_stereo_goovis.launch stereo_rig_name:=jhu_daVinci
# ROS2, save the rig name as environment variable
export RIG=jhu_dVRK
ros2 launch dvrk_video decklink_stereo_goovis.launch.py stereo_rig_name:=${RIG}
Mono
The following example is based on a video4linux compatible source:
roslaunch dvrk_video gscam_v4l.launch camera_name:=depstech
11.5.5.3. Calibrate the camera
Stereo
The calibration is performed using the ROS provided application, please refer to their documentation for the parameters (http://wiki.ros.org/camera_calibration). You need to make sure the video stream is started and you are using the correct rig name.
# ROS 1
rosrun camera_calibration cameracalibrator.py --approximate 0.1 --size 12x10 --square 0.0045 right:=/jhu_daVinci/right/image_raw left:=/jhu_daVinci/left/image_raw left_camera:=/jhu_daVinci/left right_camera:=/jhu_daVinci/right
The command line above assumes you’re using a 12x10 calibration grid
and the size of each square is 4.5 mm. Once the calibration is
performed, don’t forget to “save” and “commit” using the GUI. You should
now have two new files in the catkin package you created for the
stereo rig under calibrations: left.yaml and right.yaml.
You can find some calibration checkerboards ready to print in the
assets directory. Make sure the scale is correct after printing.
The simplest solution is to measure 10 consecutive squares and verify
that it’s 10 times the claimed square size in mm. Also to note, the
checkerboard size (e.g. 12x10) is based on the number of corners
between the squares. For example, the 12x10 actually has 13x11
squares.
For ROS 2, there are a few differences:
# ROS 2
ros2 run camera_calibration cameracalibrator -c ${RIG} --approximate 0.1 --size 8x5 --square 0.01 --no-service-check --ros-args --remap right:=/${RIG}/right/image_raw --remap left:=/${RIG}/left/image_raw
Once the calibration is finished (keep an eye on the terminal behind the GUI), make sure you save the results (big ugly round button on the right). After the results are saved, do:
# create a directory in existing package
mkdir -p ~/ros2_ws/src/dvrk/dvrk_video/calibrations/${RIG}
# extract the results in the new directory
cd ~/ros2_ws/src/dvrk/dvrk_video/calibrations/${RIG}
tar zxvf /tmp/calibrationdata.tar.gz
# rebuild
cd ~/ros2_ws
colcon build
Mono
The only difference is the parameters:
rosrun camera_calibration cameracalibrator.py --size 12x10 --square 0.0045 image:=/depstech/image_raw camera:=/depstech
11.5.5.4. Restart the video using the calibration
At that point, you need to stop the launch file used for the video
acquisition and restart it with the stereo_proc parameter set to
True. This will add a ROS node to compute the rectified images
and publish the camera parameters needed for the camera registration.
Stereo
# ROS 1
roslaunch dvrk_video decklink_stereo_goovis.launch stereo_rig_name:=jhu_daVinci stereo_proc:=True
# ROS 2
ros2 launch dvrk_video decklink_stereo_goovis.launch.py stereo_rig_name:=${RIG}
Mono
roslaunch dvrk_video gscam_v4l.launch camera_name:=depstech mono_proc:=True
11.5.5.5. RViz
Use RViz to display both channels at the same time. Add image, select topic and then drop image to separate screen/eye on the HRSV display. You can save your settings so every time you start RViz you will have both images.
References: