ROS--双目相机标定中遇到的问题

ROS–双目相机标定中遇到的问题

现象

使用两个usb_cam分别发布image_raw话题后(如官网上所要求的),再执行rosrun camera_calibration cameracalibrator.py … 进行标定时,窗口变黑,无响应。

反省

这个问题从刚开始弄双目标定就遇到,起始原因是使用两个独立的摄像机代替双目摄像机。之后为了解决这个问题,去使用ROS书上的代码,但是由于版本比较老,导致机器上编译源码一直有错误,不断尝试各种方法也没有解决;而且代码工程量大,导致一直没有真正理解源代码。直到约两三个月后的2018.01.26实在走投无路,从头开始一步一步排查的时候发现了官网上一直没有细看的文档。

解决

文档里面这段话太重要了!如下:

3.1.1 Unsynchronized Stereo
By default, the image_pipeline assumes that stereo cameras are triggered to capture images simultaneously, and that matching image pairs have identical timestamps. This is the ideal situation, but requires hardware support.
Starting in Diamondback, you will be able to calibrate stereo pairs that are not (or inexactly) synchronized.
To enable approximate timestamp matching, give the –approximate=0.01 option. This permits a “slop” of 0.01s between image pairs. If you still don’t see a display window, or it is sporadically updated, try increasing the slop.

分析

双目相机在硬件上将两个摄像机集成到一起,会将两个相机图像打包后一起进行发送,所以左右图像是同步的。但是如果使用两个单目摄像机代替双目相机时就不能保证收到的左右图像是同一时刻的,这就不满足标定程序cameracalibrator.py中对左右图像时间戳相同的要求,所以会出现上述窗口黑掉无反应的情况。所幸官网对这种情况作了支持,如上文所示,在只要加入–approximate=0.01即可,如果还没有反应可以尝试增大0.01这个值。

例子

  • 单独运行
$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 --approximate=0.01 right:=/my_stereo/right/image_raw left:=/my_stereo/left/image_raw right_camera:=/my_stereo/right left_camera:=/my_stereo/left
  • 在launch文件的node中
"$(arg camera)" name="cameracalibrator"
  pkg="camera_calibration" type="cameracalibrator.py"
  args="--approximate=0.01 --size 8x6 --square 0.028" output="screen">
  from="left" to="left/image_raw"/>
  from="right" to="right/image_raw"/>
  from="left_camera" to="left"/>
  from="right_camera" to="right"/>

工程源码

移步到我的github,这个工程实现了使用两个usb摄像头组成的双目相机完成双目标定以及双目测距功能,基本功能已经实现,文档还在完善中。本篇文章相关的部分可查看/launch/stereo_calibration.launch文件。

总结

所以,使用ROS要看官网文档!不要对英文有排斥!不要过度依赖课本,因为ROS版本不断更新,书本上很多东西都不适用了。

2018.01.26晚,小记,自省。

你可能感兴趣的:(ROS)