当前位置:网站首页>【ROS】usb_ Cam camera calibration

【ROS】usb_ Cam camera calibration

2022-07-06 08:34:00 Will_ Ye

1. Nagging two sentences

When we want to use the camera for measurement , You need to calibrate the camera , Otherwise, the calculated result will have a big error , The calibration includes three parts : Internal reference , External parameters and distortion parameters . So the calibration process requires the above parameters .
It was probably troublesome to do this before , Experiments and calculations are needed to get , Now through ros The open source package of can complete camera calibration in a few minutes , Appreciate !
Specific description of the internal and external parameters distortion coefficient , You can see Reference The first link inside , It's very detailed .

2. preparation

There are three things to prepare :

  • usb_cam Of ROS Start the package
  • Camera calibration ROS package
  • There is also a checkerboard for calibration

1)usb_cam Start the package
Use what I uploaded usb_cam edition , I don't know why GitHub The downloaded version is not good , This usb_cam The version is also sent by others , It's strange , I can study it later , See what's different , Both of them can turn on the camera , Just use GitHub After opening the version of ,apriltag_ros Do not output the correct value . Download here

Download after decompression , Put it in the corresponding work space in src In the document , for example catkin_ws
And then use catkin_make compile
And then use ls /dev/video* have a look usb Camera number , If

[email protected]:~/omni_ws$ ls /dev/video*
/dev/video0  /dev/video1  /dev/video2  /dev/video3

My notebook has webcam Another external camera is connected , Actually, two cameras have four numbers , In fact, only 0 and 2 Just go , They correspond to each other webcam and usb cam, The other two won't work , And then modify usb_cam/launch/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>

The main thing is to modify the <param name="video_device" value="/dev/video0" /> This one is ok , The default is 0, Change to /dev/video2 Just go

Then start roslaunch usb_cam usb_cam-test.launch

If there is an image, it will succeed .
usb_cam

2)ROS Camera calibration package
Very convenient , direct apt-get You can download and use :
sudo apt-get install ros-melodic-camera-cibration

3) Print checkerboard
You can go to Google or Baidu Search for one , Something like this
chess box
Then figure out two things :
first , This is the chessboard size, For example, this one above is a 4x6 Of , Just count the intersections of the four grids. How many are there in a row , And a few in a column
the second , Determine the size of the grid , Measure according to the printed results , The picture above , I use A4 Paper printing , The side length of the printed grid is 0.026m, That is to say 2.6cm, Also measure the length and width of the lattice , See if it's really a square .
It is important to determine the above two points , The following input will use

3. Start calibration

Start the camera first , Then start the calibration procedure
roslaunch usb_cam usb_cam-test.launch
rosrun camera_calibration cameracalibrator.py --size 4x6 --square 0.026 image:=/usb_cam/image_raw camera:=/usb_cam
The second instruction above is to start the calibration procedure , You need to input the chessboard size and square Corresponding to the two values mentioned above

Then you will see the following interface :
UI On the interface of the calibration program, you can see X Y Size Skew also CALIBRATE, SAVE and COMMIT The logo of
X: Indicates the left and right position of the calibration plate in the field of view
Y: The position on the calibration plate in the lower field of view
Size: Indicates the size of the calibration plate in the field of view , In fact, it's the distance from the camera
Skew: Indicates the inclination angle of the calibration plate in the field of view

After opening the program , You can start to adjust the position of the calibration plate , Let it move and rotate in various positions in the camera's field of view , Give Way X Y Size and Skew The bar below these four values turns green , And then you can see CALIBRATE This button turns blue , Click to start calculating camera parameters , This process needs to wait for a while , Wait patiently
calibrate
When the calculation is finished , You can go to terminal See the following data
terminal
then SAVE The button will also turn blue , Click on SAVE Button will save the data to the default directory .
save
This catalog is in /tmp/calibrationdata.tar.gz

path
Open the package , There are pictures just collected , And save the parameters of the camera , as follows :
zip
Put this inside ost.yaml Unzip and put it in usb_cam Of src Under the table of contents , Then change your name , such as camera_calibration20220531.yaml, I like to put these configuration files in a folder , Then write down the path

And then it's the last step , open launch file , Add one more line to import camera parameters :

<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video2" />
    <param name="image_width" value="640" />
    <param name="image_height" value="480" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_info_url" value="package://usb_cam/camera_info/camera_calibration20220531.yaml"/>
    <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>

Then follow the usual roslaunch start-up usb cam That's all right. , Then you can compare the measurement results before and after calibration , You will find that the accuracy has been greatly improved .

Reference

  1. Step1: Model 16 Camera parameters ( Internal reference 、 External reference 、 Distortion parameters ):
    https://blog.csdn.net/weixin_43206570/article/details/84797361
原网站

版权声明
本文为[Will_ Ye]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060822255473.html