ros中相机标定

今天,由于apriltag的相机定位需要输入相机内参,所以需要开始标定内参。

事先准备:
usb相机(通过usb口连接电脑):
在这里插入图片描述

标定板:
size 7x5 --square 0.028

1.安装usb_cam ROS功能包

参考:https://www.jianshu.com/p/ec0ebf7fef22;
安装usb_cam ROS功能包保证相机通过usb连接后可以传回图像数据

直接下载代码:
进入创建好的工作空间:

cd ~/catkin_ws/src
git clonehttps://github.com/bosch-ros-pkg/usb_cam.git

然后退回到工作空间,编译代码:

cd~/catkin_ws
catkin_make

编译好之后,添加编译好的文件到环境变量:

source devel/setup.bash

然后接下来测试usb_cam:
先运行usb_cam节点:

rosrun usb_cam usb_cam_node

运行上面命令发现没有显示图像,只看到摄像头打开了。这是因为ros发布的topic是/usb_cam/image_raw,我们需要打开image_view来看到摄像头输出的图像。

新打开一个终端,可以通过如下命令查看话题列表:

rostopic list

运行结果如下(现实是当前存在的话题列表,其中/usb_cam/image_raw是相机输出的图像数据)
/rosout
/rosout_agg
/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

所以我们需要运行如下命令才可以看到图像(使得image_view订阅话题/usb_cam/image_raw,显示摄像头实时拍到的图像数据):

rosrun image_view image_view image:=/usb_cam/image_raw

或者直接写launch文件,这样就不用一个终端运行node,一个终端看图像。新建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> 

其中字段的意义可按照字面理解,这里不再解释。
然后终端直接运行:

roslaunch usb_cam usb_cam_test.launch 

2.使用ROS中相机标定工具包标定内参:

参考:http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration
首先获取依赖项并编译驱动程序:

$ rosdep install camera_calibration

确保你的单目相机正在ROS上发布图像。让我们列出检查图像是否已发布的主题(这一步在1中已经做过):

$ rostopic list

该指令会列出你所有发布的话题,检查是否有图像话题,大多数ROS相机驱动程序提供的默认主题是:
/camera/camera_info
/camera/image_raw

下面运行标定节点

标定之前,您需要加载要标定的图像话题(其中size为角点参数,square为边长参数。):

$ 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
Waiting for service /camera/set_camera_info ...
Service not found

可以改为:

 rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/usb_cam/image_raw camera:=/camera --no-service-check

然后标定窗口会打开,如下图所示
在这里插入图片描述
按照下图的方式,移动标定板到特定位置,用以帮助标定:
在这里插入图片描述
  当移动标定棋盘时,你会看到校准侧边栏上的几个条的长度增加了。当“校准”按钮亮起时,您有足够的数据用于校准,可以单击“校准”查看结果。
  校准大约需要一分钟。窗户可能是灰色的,但等一下,它在工作。
  标定完成后,您将在终端中看到校准结果,校准窗口中显示标定图像:
终端输出情况如图:

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 =  [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
# oST version 5.0 parameters


[image]

width
640

height
480

[narrow_stereo/left]

camera matrix
430.215550 0.000000 306.691343
0.000000 430.531693 227.224800
0.000000 0.000000 1.000000

distortion
-0.337586 0.111612 -0.000218 -0.000030 0.0000

rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000

projection
1.000000 0.000000 0.000000 0.000000
0.000000 1.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000
  • 2
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值