1. Reference materials
ROS learning-using computer camera calibration
2. Install the usb_cam driver package
usb_cam - ROS Wiki
GitHub - ros-drivers/usb_cam: A ROS Driver for V4L USB Cameras
The usb_cam package is used to read images.
1. Install usb_cam from source code
usb_cam is used for real-time SLAM and is used with the ROS platform.
1.1 Download usb_cam source code
cd catkin_ws/src
git clone https://github.com/ros-drivers/usb_cam.git
或者
git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ..
catkin_make
source ~/catkin-ws/devel/setup.bash
1.2 Compile and install usb_cam
cd usb_cam
mkdir build
cd build
cmake ..
make
2. apt install usb_cam
Install the camera calibration package camera_calibration
and change kinetic to your own ros version.
sudo apt-get install ros-kinetic-usb-cam
After installing usb_cam
the package, there /opt/ros/kinetic/share/usb_cam/launch
will be usb_cam-test.launch
a file in which two ROS nodes are started, usb_cam_node
and image_view
.
3. usb_cam-test.launch
<launch>
<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
<param name="video_device" value="/dev/video0" />
<param name="image_width" value="640" />
<param name="image_height" value="480" />
<param name="pixel_format" value="yuyv" />
<param name="camera_frame_id" value="usb_cam" />
<param name="io_method" value="mmap"/>
</node>
<node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
<remap from="image" to="/usb_cam/image_raw"/>
<param name="autosize" value="true" />
</node>
</launch>
Parameter explanation
-
/dev/video0
It is the number of the default camera and can be changed according to the specific situation.View camera instructions:
ls /dev/video*
.
2. Start the usb_cam camera driver node
rosrun usb_cam usb_cam_node
4. Launch the camera
Run the launch file in usb_cam. If it can run successfully and the image can be seen, the installation is successful.
roslaunch usb_cam usb_cam-test.launch
If started successfully, a series of topics will be published:
rostopic list
# 输出
/usb_cam/camera_info
/usb_cam/image_raw
/usb_cam/image_raw/compressed
/usb_cam/image_raw/compressed/parameter_descriptions
/usb_cam/image_raw/compressed/parameter_updates
/usb_cam/image_raw/compressedDepth
/usb_cam/image_raw/compressedDepth/parameter_descriptions
/usb_cam/image_raw/compressedDepth/parameter_updates
/usb_cam/image_raw/theora
/usb_cam/image_raw/theora/parameter_descriptions
/usb_cam/image_raw/theora/parameter_updates
Among them, usb_cam
is a namespace.
5. Display camera image
rosrun image_view image_view image:=/usb_cam/image_raw
3. Camera calibration (monocular)
Single target calibration: How to Calibrate a Monocular Camera
Dual target calibration: How to Calibrate a Stereo Camera
camera_calibration - ROS Wiki
Camera Calibration and 3D Reconstruction
Calibration and use of monocular and binocular cameras under ROS&OpenCV
ROS officially provides the camera_calibration package for monocular and dual-object calibration. This package uses the Zhang Zhengyou calibration method in opencv.
1. Installationcamera_calibration
Install the camera calibration package camera_calibration
and change kinetic to your own ros version.
rosdep install camera_calibration
或者
sudo apt-get install ros-kinetic-camera-calibaration
rostopic list
# 输出
/camera/camera_info
/camera/image_raw
2. Key steps for camera calibration
2.1 Prepare calibration plate
2.2 Start the camera calibration package
camera_calibration
cameracalibrator.py
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.0254 image:=/usb_cam/image_raw camera:=/usb_cam
Parameter explanation
–size
:Display corner point size;–square
: Specify the size of the grid. We use the black and white grid printed on A4 paper, and the size is 25.4 mm=0.0254 m;image
: Indicates which Topic image data is used.
2.3 Moving the calibration plate
After calibration starts, on the right side of the GUI screen, you can see bar controls labeled X, Y, Size, and Skew. Keep moving the calibration plate. When the bar control is filled with green, it means the calibration is completed. During the calibration process, the chessboard needs to be facing the camera's field of view, moving left/right/up/down/forward/backward, and the chessboard needs to be tilted.
X控件
: Indicates the left and right movement of the calibration plate in the camera field of view;Y控件
: Indicates the up and down movement of the calibration plate in the camera field of view;Size控件
: Indicates the forward and backward movement of the calibration plate in the camera's field of view, which can be understood as the distance between the calibration plate and the camera;skew
: Tilt and rotation of the calibration plate in the camera field of view;
2.4 Calculation CALIBRATE
calibration
All bar controls turn green and CALIBRATE
the buttons change from gray to dark green. The calibration is completed. Click to CALIBRATE
start the calibration calculation. The process takes about 1-2 minutes. After the calibration is successful, the three buttons on the right are fully activated (all turn green), and the terminal will display various parameters of the camera.
2.5 Save SAVE
calibration data
Click SAVE
the button and the calibration result will be saved in the path: /tmp/calibrationdata.tar.gz
.
2.6 View calibration data
Unzip and open , you can see the calibrated pictures and calibrationdata.tar.gz
calibrated data files . The file can be extracted and renamed to any name, such as or .ost.txt
ost.yaml
ost.yaml
left.yaml
right.yaml
3. Analysisost.yaml
ost.yaml
It is the calibration file of the camera’s internal parameters, also known ascalibration data file。
image_width: 640
image_height: 480
camera_name: camera
camera_matrix:
rows: 3
cols: 3
data: [ 581.88585, 0. , 314.2472 ,
0. , 592.27138, 210.27091,
0. , 0. , 1. ]
camera_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [0.221666, -0.575455, -0.014215, 0.003895, 0.000000]
rectification_matrix:
rows: 3
cols: 3
data: [ 1., 0., 0.,
0., 1., 0.,
0., 0., 1.]
projection_matrix:
rows: 3
cols: 4
data: [ 591.88599, 0. , 315.96148, 0. ,
0. , 603.39893, 205.72873, 0. ,
0. , 0. , 1. , 0. ]
Parameter explanation
image_width
,image_height
: indicates the length and width of the image;camera_name
:Camera name;camera_matrix
: Camera intrinsic parameter matrix;distortion_model
:Specify the type of distortion model;distortion_coefficients
: Distortion coefficient matrix;rectification_matrix
: Correction matrix, usually unit matrix;projection_matrix
: Projection matrix from world coordinates to image plane;
4. Image dedistortion
Once you have the correction data, you can use image_proc
the functions provided by the package to dedistort the camera image. image_proc
The camera calibration parameters will be extracted from the specified topic. This topic defaults to a namespace and can be specified, for example /xxx_cam/camera_info
:xxx_cam
ROS_NAMESPACE=usb_cam rosrun image_proc image_proc
image_proc
The processed images will be published to /xxx_camera/image_rect
and image_rect_color
, image_rect
which are grayscale images image_rect_color
and color images.
How to publish YAML correction data file to /xxx_camera/camera_info
topic? It is relatively simple for a monocular camera. When starting usb_cam
, camera_info_url
just specify parameters for it, and camera_info_url
the parameters point to the yaml correction data file. Modify usb_cam-test.launch
the file and add the following:
<param name="camera_info_url" type="string" value="file://$(find usb_cam)/ost.yaml" />
<!-- param name="camera_info_url" type="string" value="file:///home/yoyo/ost.yaml" / -->
In this way, usb_camera
the camera's yaml correction data file will be loaded at startup. In fact, the class provided by the package usb_camera
is called to read the yaml correction parameter file and publish it.camera_info_manager
CameraInfoManager
5. Summary
- When colored lines appear on the calibration board (checkerboard), it indicates that the current picture is effectively captured;
- When the calibration board almost fills the camera interface, the success rate of capturing images is the highest;
- After each move, please keep the calibration plate motionless until a highlight prompt appears in the window;
- In order to obtain a good calibration result, the calibration plate should appear in every position of the camera's field of view as much as possible. Move the calibration plate to the left, right, top, bottom, tilt, level, etc. of the field of view, and move the calibration plate as often as possible.