ros調用攝像頭
1、安裝功能包
只能在
catkin_ws/src 目錄下創建功能包,編譯
cd catkin_ws/src git clone https://github.com/bosch-ros-pkg/usb_cam.git cd .. catkin_make
2、
運行usb_cam_node
先打開新的終端,運行roscore
新版本的usb_cam包在launch文件夾下有自帶的launch文件,名叫usb_cam-test.launch,我們可以直接cd到這個文件夾下運行它。再打開新終端:
cd catkin_ws/src/usb_cam/launch
roslaunch usb_cam-test.launch
出現如下錯誤:需要source 一下,環境變量未設置

source ~/catkin_ws/devel/setup.bash
如下error,則需要安裝
image-view
ERROR: cannot launch node of type [image_view/image_view]: image_view
sudo apt-get install ros-kinetic-image-view
重新運行launch文件就可以正常彈出攝像頭圖像窗口
在usb_cam-test.launch文件中,默認用的video0,打開本地攝像頭,改成video1,就可以打開外接攝像頭

使用USB攝像頭,將默認的改為video1(注意需要重新編譯一下)

<launch> <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" > pkg--功能包名 name--節點運行名 type--節點可執行文件的名字 output--節點標准輸出打印到終端(默認是終端日志) <param name="video_device" value="/dev/video0" /> param--參數說明 ,每個活躍的節點可以通過ros::param::get()接口獲取parameter的值 <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"> respawn--復位屬性,該節點停止時,會自動重啟 <remap from="image" to="/usb_cam/image_raw"/> remap--重映射 將已有的包直接改名拿來用 <param name="autosize" value="true" /> </node> </launch>
其他屬性說明
require ="true" :必要節點,當該節點終止時,launch文件中其他節點也被終止
ns="namespace" 為節點內的相對名稱添加命名空間前綴