相机标定流程记录

参考
camera_calibration标定wiki教程
git源码
可以标定单目和双目
使用教程-摄像头标定跑通ORB_SLAM2
自动生成相机标定的标定板文件的网站
https://guyuehome.com/34592
添加链接描述

1: 单相机标定

硬件:使用相机logi 720P usb相机
材料:9×7棋盘标定板

  • 1.1 下载camera_calibration并编译;

  • 1.2 启动usb摄像头并查看话题;

  • 1.3 启动标定程序,填入对应的相机话题;

    rosrun camera_calibration cameracalibrator.py 
    --size 8x6 
    --square 0.108 
    image:=/usb_cam/image_raw 
    camera:=/usb_cam
    
  • 1.4 移动标定板:
    为了达到良好的标定效果,需要在摄像机周围移动标定板,并完成以下基本需求:
    (1)移动标定板到画面的最左、右,最上、下方。
    (2)移动标定板到视野的最近和最远处。
    (3)移动标定板使其充满整个画面。
    (4)保持标定板倾斜状态并使其移动到画面的最左、右,最上、下方 。
    当标定板移动到画面的最左、右方时,此时,窗口的x会达到最小或满值。同理,y指示标定板的在画面的上下位置,size表示标定板在视野中的距离,也可以理解为标定板离摄像头的远近。skew为标定板在视野中的倾斜位置。每次移动之后,请保持标定板不动直到窗口出现高亮提示。
    直到条形变为绿色。

  • 1.5 标定:
    当calibration按钮亮起时,代表已经有足够的数据进行摄像头的标定,此时请按下calibration并等待一分钟左右,标定界面会变成灰色,无法进行操作,属于正常情况。
    等待即可。

  • 1.6 保存参数:
    点击SAVE
    终端出现: (‘Wrote calibration data to’, ‘/tmp/calibrationdata.tar.gz’)
    在该路径下即可查看标定的图片以及参数。
    ost.yaml文件内容:

image_width: 640
image_height: 480
camera_name: narrow_stereo
camera_matrix:
  rows: 3
  cols: 3
  data: [ 870.33114,    0.     ,  327.26967,
            0.     ,  873.3878 ,  209.56985,
            0.     ,    0.     ,    1.     ]
distortion_model: plumb_bob
distortion_coefficients:
  rows: 1
  cols: 5
  data: [0.144103, 0.206440, -0.020122, -0.009225, 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: [ 906.16785,    0.     ,  323.72493,    0.     ,
            0.     ,  908.15479,  204.82543,    0.     ,
            0.     ,    0.     ,    1.     ,    0.     ]

参数说明:
camera_matrix:
rows: 3
cols: 3
data: [fx, 0. , cx,
0. , fy, cy,
0. , 0. , 1. ]
distortion_coefficients:
rows: 1
cols: 5
data: [k1, k2, p1,p2, k3]

以ORB3的配置文件为例,对应的相机畸变参数如下:

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
Camera.type: "PinHole"

# Camera calibration and distortion parameters (OpenCV) 
Camera.fx: 870.331144
Camera.fy: 873.3878
Camera.cx: 327.26967
Camera.cy: 209.56985

Camera.k1: 0.144103
Camera.k2: 0.206440
Camera.p1: -0.020122
Camera.p2: -0.009225

Camera.width: 640
Camera.height: 480

2: 双目相机标定

  • 开启zed_mini 相机的节点
roslaunch zed_wrapper zedm.launch 
  • 开启标定程序
rosrun camera_calibration cameracalibrator.py --approximate 0.1 --size 8x6 --square 0.027 right:=/zedm/zed_node/right/image_rect_color left:=/zedm/zed_node/left/image_rect_color right_camera:=/zedm/zed_node/right left_camera:=/zedm/zed_node/left --no-service-ch
  • 终端输出的结果:
Left:
D = [0.04341428595404559, 0.0063062911142718675, -0.00590483473558879, 0.008338714005401374, 0.0]
K = [344.73065442876094, 0.0, 346.14033814737127, 0.0, 348.9098838238809, 182.41429403785187, 0.0, 0.0, 1.0]
R = [0.9971424782657199, -0.00010533884975872145, -0.07554380809719045, 0.00016323254526355447, 0.9999996977367338, 0.0007601852255737136, 0.07554370518603501, -0.0007703441878441629, 0.9971421940609061]
P = [400.67591662983256, 0.0, 404.1593208312988, 0.0, 0.0, 400.67591662983256, 180.19606399536133, 0.0, 0.0, 0.0, 1.0, 0.0]
Right:
D = [0.07027877165925192, -0.03970421037659701, -0.0020034498123841253, 0.002852648746719803, 0.0]
K = [351.9476116643659, 0.0, 337.45009612208867, 0.0, 355.5767350166511, 181.88544015472607, 0.0, 0.0, 1.0]
R = [0.9951228188104182, -0.0004266412574459296, -0.09864275675408246, 0.0003510070502755542, 0.9999996309890489, -0.0007841019174973316, 0.098643054884053, 0.0007456534072953003, 0.9951226013532896]
P = [400.67591662983256, 0.0, 404.1593208312988, -24.5955973646918, 0.0, 400.67591662983256, 180.19606399536133, 0.0, 0.0, 0.0, 1.0, 0.0]
self.T = [-0.06108587804764467, 2.6189486694306414e-05, 0.006055211774328044]
self.R = [0.9997311528799743, 0.0001701927470757537, 0.023186051748980623, -0.00020586021457941761, 0.9999987992580249, 0.0015359375248953976, -0.023185762503088354, -0.001540297678103584, 0.9997299874967307]
# oST version 5.0 parameters
[image]
width
672
height
376
[narrow_stereo/left]
camera matrix
344.730654 0.000000 346.140338
0.000000 348.909884 182.414294
0.000000 0.000000 1.000000
distortion
0.043414 0.006306 -0.005905 0.008339 0.000000
rectification
0.997142 -0.000105 -0.075544
0.000163 1.000000 0.000760
0.075544 -0.000770 0.997142
projection
400.675917 0.000000 404.159321 0.000000
0.000000 400.675917 180.196064 0.000000
0.000000 0.000000 1.000000 0.000000
# oST version 5.0 parameters
[image]
width
672
height
376
[narrow_stereo/right]
camera matrix
351.947612 0.000000 337.450096
0.000000 355.576735 181.885440
0.000000 0.000000 1.000000
distortion
0.070279 -0.039704 -0.002003 0.002853 0.000000
rectification
0.995123 -0.000427 -0.098643
0.000351 1.000000 -0.000784
0.098643 0.000746 0.995123
projection
400.675917 0.000000 404.159321 -24.595597
0.000000 400.675917 180.196064 0.000000
0.000000 0.000000 1.000000 0.000000

2.1: 双目相机标定_usb相机

  • 开启相机的节点
roslaunch usb_cam usb_cam0.launch
roslaunch usb_cam usb_cam1.launch
  • 开启标定程序
 rosrun camera_calibration cameracalibrator.py --approximate 0.1 --size 8x6 --square 0.027 right:=/usb_cam0/image_raw left:=/usb_cam1/image_raw right_camera:=/usb_cam0 left_camera:=/usb_cam1 --no-service-c
  • 终端输出的结果:
Left:
D = [0.1393911343443342, 0.5147666031893691, 0.00041437742453712904, 0.0035973147983647986, 0.0]
K = [847.5816273944721, 0.0, 363.15840542706735, 0.0, 852.2507091078705, 255.2956782947944, 0.0, 0.0, 1.0]
R = [0.9978928037446491, 0.05162730324112382, -0.03930106607577755, -0.05156340422428274, 0.9986662374503886, 0.0026384695350317694, 0.039384864852463425, -0.0006064130053971754, 0.9992239312005193]
P = [1109.065840898741, 0.0, 357.68358612060547, 0.0, 0.0, 1109.065840898741, 254.29504013061523, 0.0, 0.0, 0.0, 1.0, 0.0]

Right:
D = [0.11545486002780049, 0.19532345803834014, 0.0007388520965654024, 0.014707783066952947, 0.0]
K = [858.0545467508896, 0.0, 332.6281000346848, 0.0, 860.1223218593785, 258.4675407788443, 0.0, 0.0, 1.0]
R = [0.9997696867742222, -0.006061427284471412, 0.02058719278213331, 0.006094840342738919, 0.9999802084582285, -0.001560645069917084, -0.02057732559323924, 0.0016857612858289814, 0.9997868432222525]
P = [1109.065840898741, 0.0, 357.68358612060547, -172.3784244525149, 0.0, 1109.065840898741, 254.29504013061523, 0.0, 0.0, 0.0, 1.0, 0.0]
# 两相机的位移
self.T = [-0.15539088579436236, 0.0009421075347366397, -0.003199799078482255]
# 两相机的旋转
self.R = [0.9965382699302481, 0.05771460242117602, -0.05983728964277743, -0.05754464489219368, 0.9983325148937773, 0.004561090888964005, 0.06000075340076477, -0.0011019860396778327, 0.9981977235087791]
# oST version 5.0 parameters


[image]

width
640

height
480

[narrow_stereo/left]
# 相机的内参
camera matrix
847.581627 0.000000 363.158405
0.000000 852.250709 255.295678
0.000000 0.000000 1.000000
# 畸变参数
distortion
0.139391 0.514767 0.000414 0.003597 0.000000

rectification
0.997893 0.051627 -0.039301
-0.051563 0.998666 0.002638
0.039385 -0.000606 0.999224

projection
1109.065841 0.000000 357.683586 0.000000
0.000000 1109.065841 254.295040 0.000000
0.000000 0.000000 1.000000 0.000000
# oST version 5.0 parameters


[image]

width
640

height
480

[narrow_stereo/right]

camera matrix
858.054547 0.000000 332.628100
0.000000 860.122322 258.467541
0.000000 0.000000 1.000000

distortion
0.115455 0.195323 0.000739 0.014708 0.000000

rectification
0.999770 -0.006061 0.020587
0.006095 0.999980 -0.001561
-0.020577 0.001686 0.999787

projection
1109.065841 0.000000 357.683586 -172.378424
0.000000 1109.065841 254.295040 0.000000
0.000000 0.000000 1.000000 0.000000

3.标定完成后使用

  1. 使用usbcam发布相机话题,使用标定完的参数文件,设置对应的camera_info_url就会发布 camera_info消息。
  2. 修改usbcam的launch文件
<launch>
  <group ns="narrow_stereo"> # 为了话题正确
  
  <node name="left" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video3" />
    <param name="image_width" value="640" />
    <param name="image_height" value="480" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="left" />
    <param name="io_method" value="mmap"/>
    
    #添加的camera info,就会发布相机标定信息;
    <param name="camera_info_url" type="string" value="file:///home/zh/catkin_ws_video/src/usb_cam-develop/config/left.yaml" />
    
  </node>
  </group>
  
  # 注释就不会有界面了
  <!-- <node name="image_left_view" pkg="image_view" type="image_view" respawn="false" output="screen"> -->
  <!-- <node name="image_left_view" pkg="image_view" type="image_view" respawn="false" output="screen">
    <remap from="image" to="narrow_stereo/left/image_raw"/>
    <param name="autosize" value="true" />
  </node> -->
</launch>
  1. 在标定完成的结果文件:left.yaml

image_width: 640
image_height: 480
camera_name: **head_camera** //需要修改
camera_matrix:
rows: 3
cols: 3
data: [847.58163, 0. , 363.15841,
0. , 852.25071, 255.29568,
0. , 0. , 1. ]
camera_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [0.139391, 0.514767, 0.000414, 0.003597, 0.000000]
rectification_matrix:
rows: 3
cols: 3
data: [ 0.9978928 , 0.0516273 , -0.03930107,
-0.0515634 , 0.99866624, 0.00263847,
0.03938486, -0.00060641, 0.99922393]
projection_matrix:
rows: 3
cols: 4
data: [1109.06584, 0. , 357.68359, 0. ,
0. , 1109.06584, 254.29504, 0. ,
0. , 0. , 1. , 0. ]

  1. 查看话题列表
    相机标定流程记录_第1张图片
  2. rostopic echo /narrow_stereo/left/camera_info

相机标定流程记录_第2张图片

你可能感兴趣的:(ros,传感器,标定,自动驾驶)