本文已参与「新人创作礼」活动,一起开启掘金创作之路。
💐 兄dei
,点个赞呗! 💐
🍀 兄dei
,你的随手一赞,就是对我莫大的鼓励! 🍀
🌺 兄dei
,每日一赞,发大财
,行大运
哦! 🌺
1 安装依赖
1、安装依赖
rosdep install camera_calibration
注意:
我的系统是Mint19.04
,因此安装的过程中会报如下错误:
(base) shl@zhihui-mint:~$ rosdep install camera_calibration
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
camera_calibration: Unsupported OS [mint]
(base) shl@zhihui-mint:~$
错误解决方式:查看Mint对应的Ubuntu的版本号,然后再安装:
1)查看Mint对应的Ubuntu版本号
cat /etc/os-release
(base) shl@zhihui-mint:~$ cat /etc/os-release
NAME="Linux Mint"
VERSION="19.3 (Tricia)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 19.3"
VERSION_ID="19.3"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.linuxmint.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=tricia
UBUNTU_CODENAME=bionic
(base) shl@zhihui-mint:~$ rosdep install camera_calibration --os=ubuntu:bionic
#All required rosdeps installed successfully
(base) shl@zhihui-mint:~$
2)安装camera_calibration包
rosdep install camera_calibration --os=ubuntu:bionic
安装:camera-calibration
包,我的Mint19.3对应的是Ubuntu18.3,对应的ros的版本号为:melodic
因此Ubuntu18.04对应的ros版本号为melodic
:
sudo apt install ros-melodic-camera-calibration
2 运行标定节点
2.1 rocore
roscore
roscore
2.2 启动摄像头驱动程序
1、关于启动摄像头驱动程序,参考这篇博客,我这里使用的是usb_cam驱动
roslaunch usb_cam-test.launch
2、确保单目相机正在通过ROS发布图像。列出主题来检查图像是否已发布:
rostopic list
这会显示所有已发布的主题,检查是否有image_raw主题
。大多数ROS相机驱动程序提供的默认主题
是
/camera/camera_info
/camera/image_raw
我自己的查看如下:
(base) shl@zhihui-mint:~$ rostopic list
/rosout
/rosout_agg
/usb_cam/camera_info
/usb_cam/image_raw
(base) shl@zhihui-mint:~$
注意:
我的显示的名字是
/usb_cam
,这个在下面加载图像主题的时候需要注意
2.3 加载将要标定的图像主题
1、首先找到你的标定程序cameracalibrator.py
(base) shl@zhihui-mint:~$ find /opt/ros -name cameracalibrator.py
/opt/ros/melodic/lib/camera_calibration/cameracalibrator.py
(base) shl@zhihui-mint:~$
2、进入标定程序目录
cd /opt/ros/melodic/lib/camera_calibration
3、加载将要标定的图像主题
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/usb_cam/image_raw camera:=/usb_cam
(base) shl@zhihui-mint:/opt/ros/melodic/lib/camera_calibration$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/usb_cam/image_raw camera:=/usb_cam
Waiting for service /usb_cam/set_camera_info ...
OK
此命令运行标定结点的python脚本,其中 : (1)--size 8x6
: 为当前标定板的大小(如果你的棋盘格的小方格的个数是9x7
,那么我们这里就写--size 8x6
,因我检测棋盘格是内部小正方形角点的交点!) (2)--square 0.108
:为每个小棋盘格的边长,单位是米 (3)image:=/camera/image_raw
:标定当前订阅图像来源自名为/camera/image_raw的topic (4)camera:=/camera
:为摄像机名
注意1:
你需要使用rostopic list
查看自己的的订阅名,我使用的是USB摄像机,因此用的是上面的命令,如果你不可能就需要用下面的命令
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/camera/image_raw camera:=/camera
注意2:
如果你运行报错:Service not found
,这原因很可能是因为你的订阅名指定错误了
base) shl@zhihui-mint:/opt/ros/melodic/lib/camera_calibration$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/camera/image_raw camera:=/camera
Waiting for service /camera/set_camera_info ...
Service not found
(base) shl@zhihui-mint:/opt/ros/melodic/lib/camera_calibration$
3 开始标定
3.1 打印一张棋盘格图片
可以从这里获取 ,下面给出opencv官网给出的一张9*6内角点棋盘格,格子大小为26mm
:
3.2 具体标定过程
8×6和0.108是官方给出的标定板的尺寸,请根据自己的修改比如我的是8×6和0.0216(参考)
为了得到一个好的标定结果,应该使得标定板尽量出现在摄像头视野的各个位置里: 如标定板出现在视野中的左边,右边,上边和下边,标定板既有倾斜的,也有水平的.所以多动一动~
界面中的
x:表示标定板在视野中的左右位置。
y:表示标定板在视野中的上下位置。
size:标定板在占视野的尺寸大小,也可以理解为标定板离摄像头的远近。
skew:标定板在视野中的倾斜位置。
因此,需要移动标定板:x代表左右移动,y代表上下移动,size代表远近移动,skew代表倾斜侧角,可以上下倾,也可以左右倾。
1、通过不停的移动标定板:直到X、Y、Size、Skew四个都变成绿色
2、当四个都变绿色时,下面的三个按钮也会变成青色
,此时点击CALIBRATE
开始标定,过程大约1,2分钟
当开始标定后,可以在终端中看到看到标定的信息:
(base) shl@zhihui-mint:/opt/ros/melodic/lib/camera_calibration$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/usb_cam/image_raw camera:=/usb_cam
Waiting for service /usb_cam/set_camera_info ...
OK
*** Added sample 1, p_x = 0.616, p_y = 0.258, p_size = 0.293, skew = 0.201
*** Added sample 2, p_x = 0.379, p_y = 0.302, p_size = 0.345, skew = 0.409
*** Added sample 3, p_x = 0.301, p_y = 0.211, p_size = 0.289, skew = 0.047
*** Added sample 4, p_x = 0.405, p_y = 0.689, p_size = 0.457, skew = 0.172
*** Added sample 5, p_x = 0.306, p_y = 0.278, p_size = 0.384, skew = 0.087
*** Added sample 6, p_x = 0.373, p_y = 0.193, p_size = 0.386, skew = 0.028
*** Added sample 7, p_x = 0.486, p_y = 0.468, p_size = 0.337, skew = 0.117
*** Added sample 8, p_x = 0.619, p_y = 0.661, p_size = 0.344, skew = 0.163
*** Added sample 9, p_x = 0.527, p_y = 0.829, p_size = 0.288, skew = 0.472
*** Added sample 10, p_x = 0.530, p_y = 0.827, p_size = 0.271, skew = 0.289
*** Added sample 11, p_x = 0.816, p_y = 0.619, p_size = 0.312, skew = 0.014
*** Added sample 12, p_x = 0.579, p_y = 0.823, p_size = 0.288, skew = 0.032
*** Added sample 13, p_x = 0.602, p_y = 0.901, p_size = 0.293, skew = 0.219
*** Added sample 14, p_x = 0.511, p_y = 0.878, p_size = 0.320, skew = 0.156
*** Added sample 15, p_x = 0.413, p_y = 0.825, p_size = 0.324, skew = 0.106
*** Added sample 16, p_x = 0.427, p_y = 0.647, p_size = 0.337, skew = 0.148
*** Added sample 17, p_x = 0.664, p_y = 0.346, p_size = 0.313, skew = 0.082
*** Added sample 18, p_x = 0.529, p_y = 0.265, p_size = 0.331, skew = 0.065
*** Added sample 19, p_x = 0.563, p_y = 0.261, p_size = 0.330, skew = 0.485
*** Added sample 20, p_x = 0.498, p_y = 0.302, p_size = 0.295, skew = 0.297
*** Added sample 21, p_x = 0.522, p_y = 0.134, p_size = 0.286, skew = 0.305
*** Added sample 22, p_x = 0.586, p_y = 0.396, p_size = 0.348, skew = 0.005
*** Added sample 23, p_x = 0.444, p_y = 0.177, p_size = 0.324, skew = 0.243
*** Added sample 24, p_x = 0.377, p_y = 0.311, p_size = 0.327, skew = 0.126
*** Added sample 25, p_x = 0.171, p_y = 0.272, p_size = 0.314, skew = 0.101
*** Added sample 26, p_x = 0.287, p_y = 0.069, p_size = 0.314, skew = 0.128
*** Added sample 27, p_x = 0.109, p_y = 0.033, p_size = 0.313, skew = 0.165
*** Added sample 28, p_x = 0.455, p_y = 0.363, p_size = 0.284, skew = 0.025
*** Added sample 29, p_x = 0.409, p_y = 0.061, p_size = 0.310, skew = 0.025
*** Added sample 30, p_x = 0.441, p_y = 0.347, p_size = 0.245, skew = 0.162
*** Added sample 31, p_x = 0.382, p_y = 0.181, p_size = 0.277, skew = 0.148
*** Added sample 32, p_x = 0.330, p_y = 0.203, p_size = 0.251, skew = 0.315
*** Added sample 33, p_x = 0.274, p_y = 0.137, p_size = 0.277, skew = 0.381
*** Added sample 34, p_x = 0.335, p_y = 0.045, p_size = 0.271, skew = 0.236
*** Added sample 35, p_x = 0.645, p_y = 0.609, p_size = 0.189, skew = 0.078
*** Added sample 36, p_x = 0.262, p_y = 0.688, p_size = 0.215, skew = 0.219
*** Added sample 37, p_x = 0.324, p_y = 0.622, p_size = 0.235, skew = 0.150
*** Added sample 38, p_x = 0.258, p_y = 0.556, p_size = 0.244, skew = 0.057
*** Added sample 39, p_x = 0.253, p_y = 0.436, p_size = 0.233, skew = 0.136
*** Added sample 40, p_x = 0.288, p_y = 0.362, p_size = 0.224, skew = 0.232
*** Added sample 41, p_x = 0.264, p_y = 0.364, p_size = 0.235, skew = 0.014
*** Added sample 42, p_x = 0.191, p_y = 0.531, p_size = 0.242, skew = 0.195
*** Added sample 43, p_x = 0.016, p_y = 0.543, p_size = 0.164, skew = 0.076
*** Added sample 44, p_x = 0.078, p_y = 0.369, p_size = 0.172, skew = 0.003
*** Added sample 45, p_x = 0.126, p_y = 0.410, p_size = 0.177, skew = 0.144
*** Added sample 46, p_x = 0.197, p_y = 0.429, p_size = 0.178, skew = 0.349
*** Added sample 47, p_x = 0.424, p_y = 0.090, p_size = 0.197, skew = 0.202
*** Added sample 48, p_x = 0.289, p_y = 0.905, p_size = 0.258, skew = 0.314
*** Added sample 49, p_x = 0.370, p_y = 0.862, p_size = 0.237, skew = 0.240
*** Added sample 50, p_x = 0.030, p_y = 0.835, p_size = 0.237, skew = 0.344
*** Added sample 51, p_x = 0.899, p_y = 0.230, p_size = 0.257, skew = 0.138
*** Added sample 52, p_x = 0.550, p_y = 0.498, p_size = 0.184, skew = 0.006
*** Added sample 53, p_x = 0.481, p_y = 0.548, p_size = 0.234, skew = 0.037
*** Added sample 54, p_x = 0.328, p_y = 0.740, p_size = 0.167, skew = 0.520
*** Added sample 55, p_x = 0.350, p_y = 0.697, p_size = 0.181, skew = 0.366
*** Added sample 56, p_x = 0.379, p_y = 0.735, p_size = 0.176, skew = 0.796
*** Added sample 57, p_x = 0.243, p_y = 0.747, p_size = 0.154, skew = 0.347
*** Added sample 58, p_x = 0.333, p_y = 0.489, p_size = 0.155, skew = 0.150
**** Calibrating ****
D = [-0.3499780364596218, 0.10509003071685562, 0.001679044863502849, 0.008650165715176933, 0.0]
K = [429.8550308646715, 0.0, 302.68475082388386, 0.0, 428.69315916472806, 233.4834792745656, 0.0, 0.0, 1.0]
R = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P = [329.21832275390625, 0.0, 308.72734114651394, 0.0, 0.0, 374.89495849609375, 232.52836954700615, 0.0, 0.0, 0.0, 1.0, 0.0]
None
# oST version 5.0 parameters
[image]
width
640
height
480
[narrow_stereo]
camera matrix
429.855031 0.000000 302.684751
0.000000 428.693159 233.483479
0.000000 0.000000 1.000000
distortion
-0.349978 0.105090 0.001679 0.008650 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
329.218323 0.000000 308.727341 0.000000
0.000000 374.894958 232.528370 0.000000
0.000000 0.000000 1.000000 0.000000
('Wrote calibration data to', '/tmp/calibrationdata.tar.gz')
('Wrote calibration data to', '/tmp/calibrationdata.tar.gz')
D = [-0.3499780364596218, 0.10509003071685562, 0.001679044863502849, 0.008650165715176933, 0.0]
K = [429.8550308646715, 0.0, 302.68475082388386, 0.0, 428.69315916472806, 233.4834792745656, 0.0, 0.0, 1.0]
R = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P = [329.21832275390625, 0.0, 308.72734114651394, 0.0, 0.0, 374.89495849609375, 232.52836954700615, 0.0, 0.0, 0.0, 1.0, 0.0]
# oST version 5.0 parameters
[image]
width
640
height
480
[narrow_stereo]
camera matrix
429.855031 0.000000 302.684751
0.000000 428.693159 233.483479
0.000000 0.000000 1.000000
distortion
-0.349978 0.105090 0.001679 0.008650 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
329.218323 0.000000 308.727341 0.000000
0.000000 374.894958 232.528370 0.000000
0.000000 0.000000 1.000000 0.000000
(base) shl@zhihui-mint:/opt/ros/melodic/lib/camera_calibration$
3、然后点击Save
按钮,会把标定的文件信息保存到:/tmp/calibrationdata.tar.gz
路径下
calibrationdata.tar.gz
压缩文件中,会存储标定过程中的图片,还有就是标定的参数相机参数文件,如下:
ost.txt
文件内容:
# oST version 5.0 parameters
[image]
width
640
height
480
[narrow_stereo]
camera matrix
429.855031 0.000000 302.684751
0.000000 428.693159 233.483479
0.000000 0.000000 1.000000
distortion
-0.349978 0.105090 0.001679 0.008650 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
329.218323 0.000000 308.727341 0.000000
0.000000 374.894958 232.528370 0.000000
0.000000 0.000000 1.000000 0.000000
ost.yaml
文件内容:
image_width: 640
image_height: 480
camera_name: narrow_stereo
camera_matrix:
rows: 3
cols: 3
data: [ 429.85503, 0. , 302.68475,
0. , 428.69316, 233.48348,
0. , 0. , 1. ]
camera_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [-0.349978, 0.105090, 0.001679, 0.008650, 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: [ 329.21832, 0. , 308.72734, 0. ,
0. , 374.89496, 232.52837, 0. ,
0. , 0. , 1. , 0. ]
参考:blog.csdn.net/learning_to… # 相机和雷达的联合标定 参考:blog.csdn.net/learning_to… # ros对相机标定,同时包含标定的理论知识,还有就是去图像畸变的实现 参考:blog.csdn.net/qq_41746268… # ros标定参考 参考:wiki.ros.org/camera_cali… # ros官网给出的相机标定教程 参考:zhuanlan.zhihu.com/p/24651968 # 相机标定的理论知识,很详细 参考:wiki.ros.org/camera_cali… # ros官方单目相机的标定教程 参考:blog.csdn.net/sinat_16643… # 关于标定参数的解释
今天的文章使用ros自带的标定工具标定相机的内参和外参分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/20680.html