1、首先看usb_cam:
直接下载代码:
进入创建好的工作空间:
cd ~/catkin_ws/src
git clonehttps://github.com/bosch-ros-pkg/usb_cam.git
然后退回到工作空间,编译代码:
cd~/catkin_ws
catkin_make
编译好之后,添加编译好的文件到环境变量:
sourcedevel/setup.bash
然后接下来测试usb_cam:
先运行usb_cam节点:
rosrun usb_cam usb_cam_node
运行上面命令发现没有显示图像,只看到摄像头打开了。这是因为ros发布的topic是/usb_cam/image_raw。新打开一个终端,可以通过如下命令查看:
rostopic list
结果如下:
/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
所以我们需要运行如下命令才可以看到图像:
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