[ROS] 安装 USB Camera 驱动并调用
在 ROS 系统中,想要使用 USB 摄像头需要安装相应的驱动程序。这里以常用的 usb_cam 为例来说明如何安装给 ROS 安装 USB 摄像头。
0、安装环境:
Ubuntu版本:14.04 LTS
ROS版本:indigo (1.11.13)
1、进入ROS工作区(假设为~/catkin-ws),新建 usb_cam 目录,并在其下新建 src 目录:
1 2 | $ cd ~/catkin-ws/ $ mkdir -p usb_cam/src |
2、进入 src 目录,使用 git 下载 usb_cam 源码:
1 2 | $ cd usb_cam/src $ git clone https://github.com/bosch-ros-pkg/usb_cam.git |
3、退出 src 目录运行 catkin_make 并配置运行环境:
1 2 3 | $ cd .. $ catkin_make $ source ~/catkin-ws/devel/setup.bash |
可以测试一下是否配置好了:
1 | roscd usb_cam |
4、运行 usb_cam:
1 | rosrun usb_cam usb_cam_node |
当然这里只能看到摄像头打开并不会看到图像,如果想要看下当前的图像可以使用 image_view,因为 usb_cam 默认发布 /usb_cam/image_raw 这样的 topic,因此查看命令为:
1 | rosrun image_view image_view image:=/usb_cam/image_raw |
如果一切顺利,你就可以看到一个摄像头的实时视频窗口了。
5、使用自定义 launch 文件设置摄像头:
usb_cam 给了我们一个默认的 launch 文件在如下目录
1 | ~/catkin-ws/usb_cam/src/usb_cam/launch/usb_cam-test.launch |
如果想要自定义一个我们自己的launch文件,我们可以复制这个文件为一个 usb_cam.launch,然后打开这个文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <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> |
其中 /div/video0 表示是第一个摄像头,如果你有多个摄像头,可以将此改为 /div/video1 等等。想要查看当前连接设备,使用如下命令即可:
1 | ls /dev/video* |
其余参数请见参考文献[1]的说明。
修改好后运行这个文件:
1 | roslaunch usb_cam usb_cam.launch |
错误提示:
1、Error: package 'image_view' not found
如果出现:
1 | [rospack] Error: package 'image_view' not found |
表明你的 image_view 没有安装,可以执行以下命令安装即可:
1 | sudo apt-get install ros-indigo-image-view |
参考文献:
[1] http://wiki.ros.org/usb_cam
[2] http://answers.ros.org/question/197651/how-to-install-a-driver-like-usb_cam/
[3] 更多 ros camera 选择:http://answers.ros.org/question/9089/what-driver-should-i-use-for-my-usb-camera/
Do you have more great arctlies like this one?
I have no idea what do you mean by "like" this one. But if you mean some articles targeted on "Robot" or "ROS", you are free to view them on the following category:
https://www.liuxiao.org/category/robots/
hello,how can I solve it?
/home/tju530/catkin ws/src/usb_cam-develop/src/usb_cam.cpp: In member functionvoid usb cam::UsbCam::mjpeg2rgb(char*,int,char*,int)':/home/tju530/catkin ws/src/usb cam-develop/src/usb_cam.cpp:503:61:
error;"avcodec send packet’was not declared in this scopedecoded_len = avcodec_send packet(avcodec_context_,&avpkt);avcod
/home/tju530/catkin ws/src/usb_cam-develop/src/usb cam.cpp:518:75: error:ec receive frane was not declared in this scopeint error code = avcodec receive frame(avcodec context, avframe camera );
bunti
monline 7 dg8
0
1o aotget
usb cam-develop/CHakeFiles/usb cam.dir/build.make:65: recipe for target "usb cam-develop/CHakeFiles/usb cam.dir/src/usb cam.cpp.o' failedmake[2]: ##* Tusb can-develop/CHakeFiles/usb cam.dir/src/usb cam.cpp.o] Error 1CHakeFiles/Makefile2:418: recipe for target 'usb cam-develop/CHakeFiles/usb candir/all'failedmake[1]: es [usb cam-develop/CHakeFiles/usb cam.dir/all] Error 2Makefile:143: recipe for target 'all' failedata[all] Error 2