ROS中使用摄像头的问题

一、前言

在ROS下常用的主要有两种驱动包:usb_cam和uvc_cam

我这里用的是usb_cam包

第一次使用首先要安装这个包,安装完了之后就可以很方便的运行摄像头节点了

二、安装usb_cam包

首次使用需要下载安装usb_cam包

这里参考博客:How to Use a Webcam in ROS with the usb_cam Package

三种方式安装:

1、可以直接用apt-get install命令

$ sudo apt-get install ros-hydro-bosch-drivers
注意上面的hydro要替换成你的ROS版本

2、也可以下载usb_cam源代码自己编译

$ cd catkin_ws
$ svn co https://bosch-ros-pkg.svn.sourceforge.net/svnroot/bosch-ros-pkg/trunk/stacks/bosch_drivers
$ rospack profile
$ roscd usb_cam
$ rosmake --rosdep-install

上面的catkin_ws是你创建的catkin工作空间的名字,一般会将软件包建在catkin空间中

3、还有第三种安装方式,我是用这种方法下载并编译的

$ cd catkin_ws/src
$ git clone https://github.com/bosch-ros-pkg/usb_cam.git
$ cd ..
$ catkin_make

需要确保usb_cam安装过程中没有错误

  • Bug / feature tracker: https://github.com/bosch-ros-pkg/usb_cam/issues
  • Source: git https://github.com/bosch-ros-pkg/usb_cam.git (branch: master)
  • ROS wiki:http://wiki.ros.org/usb_cam

三、运行usb_cam_node开启摄像头

打开一个新的终端,运行roscore
$ roscore
新版本的usb_cam包在launch文件夹下有自带的launch文件,名叫usb_cam-test.launch
我们可以直接cd到这个文件夹下运行它
$ cd
$ cd catkin_ws/src/usb_cam/launch
$ roslaunch usb_cam-test.launch
如果工作空间的usb_cam包中不带这个launch文件我们就要新建它:
打开catkin_ws/src/usb_cam/launch文件夹,在其中新建一个文件,把名字改为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>
保存,并关闭这个文件。
然后同样要cd到launch文件夹才能运行这个文件:
$ cd
$ cd catkin_ws/src/usb_cam/launch
$ roslaunch usb_cam-test.launch

ROS中使用摄像头的问题_第1张图片

四、遇到的问题

1、报错[usb_cam-test.launch] is not a launch file name
运行完roslaunch usb_cam-test.launch后报错说usb_cam-test.launch不是一个launch文件,这是因为没有cd到catkin_ws/src/usb_cam/launch文件夹下,系统找不到这个launch文件
2、对于有些节点没有跑起来的情况,可以从下载的catkin_ws/src/usb_cam中找到相应的.py文件然后用cp命令复制到opt/ros/hydro/的相应文件夹下
这篇文章: 配置ROS工作空间catkin+rosbuild对于理解ROS的文件系统很有帮助







你可能感兴趣的:(安装,驱动,ROS,摄像头,usb_cam)