最新消息:

ROS与深度相机入门教程-在ROS使用webcam摄像头(内置或外置)

ROS1/一代机器人系统 少儿编程 2342浏览 0评论
ROS与深度相机教程

ROS与深度相机入门教程-在ROS使用webcam摄像头(内置或外置)

说明:

  • 介绍如何ros中使用内置或外置webcam摄像头
  • 介绍使用uvc-camera包
  • 介绍使用usb_cam包
  • 利用ROS by example 1代码:参考rbx1的github库

笔记本自带摄像头采集图像

  • 测试环境:win7+vbox虚拟机+ubuntu14.04+indigo
  • 虚拟机使用笔记本的内置摄像头
  • 笔记本自带的摄像头的设备号一般为/dev/video0

(1)使用uvc_camera包

  • 安装uvc_camera驱动:
sudo apt-get install ros-indigo-uvc-camera
  • 安装rbx1包
$ cd ~/catkin_ws/src 
$ git clone https://github.com/ncnynl/rbx1.git
$ cd ~/catkin_ws
$ catkin_make
  • 在catkin_ws/src/rbx1/rbx1_vision/launch目录,新建uvc_camera.launch
$ cd ~/catkin_ws/src/rbx1/rbx1_vision/launch
$ touch uvc_camera.launch
$ vim uvc_camera.launch
  • 增加uvc_camera.launch
 <launch>  
   <arg name="video_device" default="/dev/video0" />  
  
   <node name="uvc_camera_node" pkg="uvc_camera" type="uvc_camera_node" output="screen">  
    <remap from="image_raw" to="/camera/rgb/image_raw" />  
       <param name="device" value="$(arg video_device)" />  
       <param name="width" value="640" />  
       <param name="height" value="480" />  
       <param name="frame_rate" value="30" />  
       <param name="exposure" value="0" />  
       <param name="gain" value="100" />   
   </node>  
 </launch>  
  • 刷新环境变量
$ rospack profile

测试:

  • 新终端,启动roscore
$ roscore 
  • 新终端,启动rbx1
roslaunch rbx1_vision uvc_camera.launch video_device:=/dev/video0 
  • 新终端,查看图像:
rosrun image_view image_view image:=/camera/rgb/image_raw 
  • 注意:如果在虚拟机里使用笔记本摄像头,可能会出现花屏。可以使用usb_cam替代

(2)使用usb_cam包

  • 安装usb_cam驱动
$ cd ~/catkin_ws/src  
$ git clone https://github.com/bosch-ros-pkg/usb_cam.git  
$ cd ~/catkin_ws  
$ catkin_make  
  • 目前新版本的rbx1已经带有usb_cam,如果没有添加如下。
  • 在catkin_ws/src/rbx1/rbx1_vision/launch目录,新建usb_cam.launch
$ cd ~/catkin_ws/src/rbx1/rbx1_vision/launch
$ touch usb_cam.launch
$ vim usb_cam.launch
  • 代码如下:
   <launch>
    <arg name="video_device" default="/dev/video0" />

    <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" clear_params="true" output="screen">

        <remap from="usb_cam/image_raw" to="/camera/rgb/image_raw" />
        <remap from="usb_cam/camera_info" to="/camera/rgb/camera_info" />

        <param name="video_device" value="$(arg video_device)" />
        <param name="image_width" value="640" />
        <param name="image_height" value="480" />
        <param name="framerate" value="30" />
        <param name="pixel_format" value="mjpeg" />
        <param name="contrast" value="32" />
        <param name="brightness" value="32" />
        <param name="saturation" value="32" />
        <param name="autofocus" value="true" />
        <param name="camera_frame_id" value="camera_link" />

    </node>
</launch>

测试:

  • 启动roscore
$ roscore
  • 启动rbx1
$ roslaunch rbx1_vision usb_cam.launch video_device:=/dev/video0 
  • 查看图像
$ rosrun image_view image_view image:=/camera/rgb/image_raw

外部摄像头采集图像

  • 检查摄像头可以用,安装guvcview或cheese
sudo apt-get install guvcview 
sudo apt-get install cheese 
  • 启动guvcview,它能显示和配置多种参数
guvcview 
  • 使用uvc_camera包和usb_cam包测试如上。

总结:

  • 从使用上利用usb_cam包对内置和外置的摄像头的支持更好。

您必须 登录 才能发表评论!