USB图像采集
功能介绍
为实现环境感知能力,机器人产品中通常会搭载摄像头以获取图像信息。USB摄像头易于获取,使用方便,通用性好,TogetheROS.Bot添加了对USB摄像头的支持,支持ROS2标准图像消息。
支持平台
平台 | 运行方式 |
---|---|
旭日X3派 | Ubuntu 20.04 |
X86 | Ubuntu 20.04 |
准备工作
旭日X3派
确认手中USB摄像头工作正常,将USB摄像头接入旭日X3派USB插槽
旭日X3派已烧录好地平线提供的Ubuntu 20.04系统镜像
旭日X3派已成功安装tros.b
确认PC机能够通过网络访问旭日X3派
X86平台
确认手中USB摄像头工作正常,将USB摄像头接入PC或服务器USB插槽
确认X86平台系统为Ubuntu 20.04,且已成功安装tros.b
使用方式
旭日X3派和X86平台使用方式相同,其中以旭日X3派为例:
通过SSH登录旭日X3派,打开
/opt/tros/share/hobot_usb_cam/launch/hobot_usb_cam.launch.py
设置USB摄像头设备名称,这里以/dev/video8为例hobot_usb_cam.launch.py from launch import LaunchDescription from launch_ros.actions import Node def generate_launch_description(): return LaunchDescription([ Node( package='hobot_usb_cam', executable='hobot_usb_cam', name='hobot_usb_cam', parameters=[ {"camera_calibration_file_path": ""}, {"frame_id": "default_usb_cam"}, {"framerate": 30}, {"image_height": 480}, {"image_width": 640}, {"io_method": "mmap"}, {"pixel_format": "mjpeg"}, {"video_device": "/dev/video8"}, {"zero_copy": "False"} ] ) ])
并通过下述命令启动USB摄像头
# 配置 tros.b 环境: source /opt/tros/local_setup.bash # launch方式启动: ros2 launch hobot_usb_cam hobot_usb_cam.launch.py
如程序输出如下信息,说明节点已成功启动
[ERROR] [1662017254.558565200] [hobot_usb_cam]: Camera calibration file: not exist! [WARN] [1662017254.559233995] [hobot_usb_cam]: get camera calibration parameters failed [INFO] [1662017254.773617972] [hobot_usb_cam]: Set resolution to 640x480 [INFO] [1662017254.803259017] [hobot_usb_cam]: Set framerate to be 30 [WARN] [1662017255.036681491] [hobot_usb_cam]: Unable to publish camera info. [INFO] [1662017255.037049326] [hobot_usb_cam]: publish image 640x480 encoding:2 size:98583 [WARN] [1662017255.072076018] [hobot_usb_cam]: Unable to publish camera info. [INFO] [1662017255.072359603] [hobot_usb_cam]: publish image 640x480 encoding:2 size:98562 [WARN] [1662017255.103836613] [hobot_usb_cam]: Unable to publish camera info. [INFO] [1662017255.104098489] [hobot_usb_cam]: publish image 640x480 encoding:2 size:98643 ...
Web端查看USB摄像头图像,另起一个终端:
# 配置 tros.b 环境: source /opt/tros/local_setup.bash # 启动webservice ros2 launch websocket hobot_websocket_service.launch.py # 启动websocket ros2 run websocket websocket --ros-args -p image_topic:=/image -p image_type:=mjpeg -p only_show_image:=true
PC打开浏览器(chrome/firefox/edge)输入http://IP:8000(IP为旭日X3派IP地址),点击左上方Web端展示即可查看USB摄像头实时画面
注意事项
USB摄像头需要进行标定,并设置相机标定文件的读取路径,否则无法发布相机内参,但不影响其它功能
设置相机标定文件读取路径,注意将
path
更换为实际的标定文件路径!具体步骤如下:# 配置 tros.b 环境: source /opt/tros/local_setup.bash # 打开/opt/tros/share/hobot_usb_cam/launch/hobot_usb_cam.launch.py,设置camera_calibration_file_path字段为实际的相机标定文件路径 # launch 方式启动 ros2 launch hobot_usb_cam hobot_usb_cam.launch.py