使用ros标定相机的内参和外参

本文涉及的产品
资源编排,不限时长
简介: 使用ros标定相机的内参和外参

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

image.png

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

opencv ——pattern.png

image.png

3.2 具体标定过程

8x6和0.108是官方给出的标定板的尺寸,请根据自己的修改比如我的是8x6和0.0216(参考

为了得到一个好的标定结果,应该使得标定板尽量出现在摄像头视野的各个位置里:
如标定板出现在视野中的左边,右边,上边和下边,标定板既有倾斜的,也有水平的.所以多动一动~

界面中的

x:表示标定板在视野中的左右位置。

y:表示标定板在视野中的上下位置。

size:标定板在占视野的尺寸大小,也可以理解为标定板离摄像头的远近。

skew:标定板在视野中的倾斜位置。

因此,需要移动标定板:x代表左右移动,y代表上下移动,size代表远近移动,skew代表倾斜侧角,可以上下倾,也可以左右倾。

image.png

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压缩文件中,会存储标定过程中的图片,还有就是标定的参数相机参数文件,如下:

image.png

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.     ]
相关实践学习
使用ROS创建VPC和VSwitch
本场景主要介绍如何利用阿里云资源编排服务,定义资源编排模板,实现自动化创建阿里云专有网络和交换机。
阿里云资源编排ROS使用教程
资源编排(Resource Orchestration)是一种简单易用的云计算资源管理和自动化运维服务。用户通过模板描述多个云计算资源的依赖关系、配置等,并自动完成所有资源的创建和配置,以达到自动化部署、运维等目的。编排模板同时也是一种标准化的资源和应用交付方式,并且可以随时编辑修改,使基础设施即代码(Infrastructure as Code)成为可能。 产品详情:https://www.aliyun.com/product/ros/
目录
相关文章
|
数据采集 数据可视化 Ubuntu
相机和livox激光雷达外参标定:ROS功能包---livox_camera_lidar_calibration 使用方法
该功能包提供了一个手动校准Livox雷达和相机之间外参的方法,已经在Mid-40,Horizon和Tele-15上进行了验证。其中包含了计算相机内参,获得标定数据,优化计算外参和雷达相机融合应用相关的代码。本方案中使用了标定板角点作为标定目标物,由于Livox雷达非重复性扫描的特点,点云的密度较大,比较易于找到雷达点云中角点的准确位置。相机雷达的标定和融合也可以得到不错的结果。
相机和livox激光雷达外参标定:ROS功能包---livox_camera_lidar_calibration 使用方法
|
3月前
|
传感器 机器人 测试技术
ROS相机内参标定详细步骤指南
本文是关于ROS相机内参标定的详细步骤指南,包括了标定的目的、原理、所需材料、具体操作流程以及标定结果的分析。文章以Ubuntu20.04和ROS1 Noetic为测试环境,适用于单目RGB相机的内参标定,使用ros-noetic-camera-calibration工具包进行操作,并提供了标定过程中的注意事项和建议。
230 1
ROS相机内参标定详细步骤指南
|
3月前
|
Ubuntu 机器人 测试技术
奥比中光 Femto Bolt相机ROS配置
这篇文章介绍了奥比中光Femto Bolt相机在ROS1 Noetic和ROS2 Humble环境下的配置过程,包括自动脚本和手动配置方法,适用于Ubuntu 20.04/22.04系统和Jetson Orin平台。
140 0
奥比中光 Femto Bolt相机ROS配置
|
机器学习/深度学习 算法 决策智能
ubuntu16.04下ROS操作系统学习笔记(六 )机器视觉-摄像头标定-ROS+OpenCv-人脸识别-物体跟踪-二维码识别(下)
ubuntu16.04下ROS操作系统学习笔记(六 )机器视觉-摄像头标定-ROS+OpenCv-人脸识别-物体跟踪-二维码识别(下)
364 0
|
存储 机器学习/深度学习 编解码
ubuntu16.04下ROS操作系统学习笔记(六 )机器视觉-摄像头标定-ROS+OpenCv-人脸识别-物体跟踪-二维码识别(上)
ubuntu16.04下ROS操作系统学习笔记(六 )机器视觉-摄像头标定-ROS+OpenCv-人脸识别-物体跟踪-二维码识别(上)
419 0
|
Web App开发 Shell 数据安全/隐私保护
Ubuntu16(ROS_Kinetic)海康威视网络摄像机(单目)内参标定
Ubuntu16(ROS_Kinetic)海康威视网络摄像机(单目)内参标定
572 0
|
机器学习/深度学习 Ubuntu 开发工具
相机和livox激光雷达外参标定:ROS功能包---livox_camera_lidar_calibration 介绍
**什么是相机与激光雷达外参标定?** 就是相机坐标系和激光雷达坐标系的TF变化。位置x,y,z 欧拉角 roll,pitch,yaw,6个变量构成一个4*4的旋转变换矩阵 标定的就是这个4维的旋转矩阵。 标定的方法有: - 基于特征 - 基于运动观测 - 基于最大化互信息 - 基于深度学习 基于特征 的方法是根据对应特征点求解PnP问题,需要标定板来获取特征 基于运动观测可以看作手眼标定问题,精度决定于相机和雷达的运动估计 基于最大化互信息认为图像灰度于反射强度具有相关性 基于深度学习需要长时间的训练并且泛化能力不高
相机和livox激光雷达外参标定:ROS功能包---livox_camera_lidar_calibration 介绍
|
1月前
|
Ubuntu 机器人 Linux
|
7天前
|
XML 算法 自动驾驶
ROS进阶:使用URDF和Xacro构建差速轮式机器人模型
【11月更文挑战第7天】本篇文章介绍的是ROS高效进阶内容,使用URDF 语言(xml格式)做一个差速轮式机器人模型,并使用URDF的增强版xacro,对机器人模型文件进行二次优化。
|
12天前
|
自动驾驶 安全 机器人
ROS2:从初识到深入,探索机器人操作系统的进化之路
【11月更文挑战第4天】ROS2的学习过程和应用,介绍DDS系统的框架和知识。

推荐镜像

更多