5.2.1 数据采集
USB 图像采集
功能介绍
为实现环境感知能力,机器人产品中通常会搭载摄像头以获取图像信息。USB 摄像头易于获取,使用方便,通用性好,TogetheROS.Bot 添加了对 USB 摄像头的支持,支持 ROS2 标准图像消息。
代码仓库:https://github.com/D-Robotics/hobot_usb_cam.git
支持平台
| 平台 | 运行方式 |
|---|---|
| RDK X3, RDK X3 Module | Ubuntu 20.04 (Foxy), Ubuntu 22.04 (Humble) |
| RDK X5, RDK X5 Module | Ubuntu 22.04 (Humble) |
| RDK S100, RDK S100P | Ubuntu 22.04 (Humble) |
| RDK S600 | Ubuntu 24.04 (Jazzy) |
| X86 | Ubuntu 20.04 (Foxy) |
准备工作
RDK 平台
-
确认手中 USB 摄像头工作正常,将 USB 摄像头接入 RDK 的 USB 插槽
-
RDK 已烧录好 Ubuntu 系统镜像
-
RDK 已成功安装 tros.b
-
确认 PC 机能够通过网络访问 RDK
X86 平台
-
确认手中 USB 摄像头工作正常,将 USB 摄像头接入 PC 或服务器 USB 插槽
-
确认 X86 平台系统为 Ubuntu 20.04,且已成功安装 tros.b
使用方式(默认 usb_pixel_format 为 mjpeg)
RDK 和 X86 平台使用方式相同,其中以 RDK 平台为例:
-
通过 SSH 登录 RDK,确认 USB 摄像头设备名称,这里以
/dev/video8为例 -
并通过下述命令启动 USB 摄像头
- Foxy
- Humble
- Jazzy
# 配置tros.b环境
source /opt/tros/setup.bash# 配置tros.b环境
source /opt/tros/humble/setup.bash# 配置tros.b环境
source /opt/tros/jazzy/setup.bash- Humble
# 配置tros.b环境
source /opt/tros/humble/setup.bash- Jazzy
# 配置tros.b环境
source /opt/tros/jazzy/setup.bash# launch方式启动:
ros2 launch hobot_usb_cam hobot_usb_cam.launch.py usb_video_device:=/dev/video8 -
如程序输出如下信息,说明节点已成功启动
[INFO] [launch]: All log files can be found below /root/.ros/log/2024-01-18-19-44-39-419588-ubuntu-3951
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [hobot_usb_cam-1]: process started with pid [3953]
[hobot_usb_cam-1] [WARN] [1705578280.808870437] [hobot_usb_cam]: framerate: 30
[hobot_usb_cam-1] [WARN] [1705578280.809851560] [hobot_usb_cam]: pixel_format_name: mjpeg
[hobot_usb_cam-1] [WARN] [1705578280.936697507] [hobot_usb_cam]: This devices supproted formats:
[hobot_usb_cam-1] [WARN] [1705578280.936858791] [hobot_usb_cam]: Motion-JPEG: 640 x 480 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.936912830] [hobot_usb_cam]: Motion-JPEG: 1920 x 1080 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.936960328] [hobot_usb_cam]: Motion-JPEG: 320 x 240 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937007285] [hobot_usb_cam]: Motion-JPEG: 800 x 600 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937053241] [hobot_usb_cam]: Motion-JPEG: 1280 x 720 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937098906] [hobot_usb_cam]: Motion-JPEG: 1024 x 576 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937144528] [hobot_usb_cam]: YUYV 4:2:2: 640 x 480 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937190068] [hobot_usb_cam]: YUYV 4:2:2: 1920 x 1080 (5 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937235858] [hobot_usb_cam]: YUYV 4:2:2: 320 x 240 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937282064] [hobot_usb_cam]: YUYV 4:2:2: 800 x 600 (20 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937328020] [hobot_usb_cam]: YUYV 4:2:2: 1280 x 720 (10 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937373518] [hobot_usb_cam]: YUYV 4:2:2: 1024 x 576 (15 Hz) -
Web 端查看 USB 摄像头图像,另起一 个终端:
- Foxy
- Humble
- Jazzy
# 配置tros.b环境
source /opt/tros/setup.bash
# 配置tros.b环境
source /opt/tros/humble/setup.bash
# 配置tros.b环境
source /opt/tros/jazzy/setup.bash
- Humble
# 配置tros.b环境
source /opt/tros/humble/setup.bash
- Jazzy
# 配置tros.b环境
source /opt/tros/jazzy/setup.bash
# 启动websocket
ros2 launch websocket websocket.launch.py websocket_image_topic:=/image websocket_only_show_image:=true
- PC 打开浏览器
Chrome/Firefox/Edge,输入IP:8000(IP 为 RDK 的 IP 地址),点击左上方 Web 端展示即可查看 USB 摄像头实时画面。
使用方式 2(usb_pixel_format 为 yuyv2rgb)
RDK 和 X86 平台使用方式相同,其中以 RDK 平台为 例:
-
通过 SSH 登录 RDK,确认 USB 摄像头设备名称,这里以
/dev/video8为例 -
并通过下述命令启动 USB 摄像头
- Foxy
- Humble
- Jazzy
# 配置tros.b环境
source /opt/tros/setup.bash# 配置tros.b环境
source /opt/tros/humble/setup.bash# 配置tros.b环境
source /opt/tros/jazzy/setup.bash- Humble
# 配置tros.b环境
source /opt/tros/humble/setup.bash- Jazzy
# 配置tros.b环境
source /opt/tros/jazzy/setup.bash# launch方式启动:
ros2 launch hobot_usb_cam hobot_usb_cam.launch.py usb_video_device:=/dev/video8 usb_pixel_format:=yuyv2rgb usb_image_width:=640 usb_image_height:=480 -
如程序输出如下信息,说明节点已成功启动
[INFO] [launch]: All log files can be found below /root/.ros/log/2024-01-18-19-44-39-419588-ubuntu-3951
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [hobot_usb_cam-1]: process started with pid [3953]
[hobot_usb_cam-1] [WARN] [1705578280.808870437] [hobot_usb_cam]: framerate: 30
[hobot_usb_cam-1] [WARN] [1705578280.809851560] [hobot_usb_cam]: pixel_format_name: yuyv2rgb
[hobot_usb_cam-1] [WARN] [1705578280.936697507] [hobot_usb_cam]: This devices supproted formats:
[hobot_usb_cam-1] [WARN] [1705578280.936858791] [hobot_usb_cam]: Motion-JPEG: 640 x 480 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.936912830] [hobot_usb_cam]: Motion-JPEG: 1920 x 1080 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.936960328] [hobot_usb_cam]: Motion-JPEG: 320 x 240 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937007285] [hobot_usb_cam]: Motion-JPEG: 800 x 600 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937053241] [hobot_usb_cam]: Motion-JPEG: 1280 x 720 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937098906] [hobot_usb_cam]: Motion-JPEG: 1024 x 576 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937144528] [hobot_usb_cam]: YUYV 4:2:2: 640 x 480 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937190068] [hobot_usb_cam]: YUYV 4:2:2: 1920 x 1080 (5 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937235858] [hobot_usb_cam]: YUYV 4:2:2: 320 x 240 (30 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937282064] [hobot_usb_cam]: YUYV 4:2:2: 800 x 600 (20 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937328020] [hobot_usb_cam]: YUYV 4:2:2: 1280 x 720 (10 Hz)
[hobot_usb_cam-1] [WARN] [1705578280.937373518] [hobot_usb_cam]: YUYV 4:2:2: 1024 x 576 (15 Hz) -
通过 hobot codec 进行编码成 mjpeg
- Foxy
- Humble
- Jazzy
# 配置tros.b环境
source /opt/tros/setup.bash# 配置tros.b环境
source /opt/tros/humble/setup.bash# 配置tros.b环境
source /opt/tros/jazzy/setup.bash- Humble
# 配置tros.b环境
source /opt/tros/humble/setup.bash- Jazzy
# 配置tros.b环境
source /opt/tros/jazzy/setup.bash# launch方式启动:
ros2 launch hobot_codec hobot_codec_encode.launch.py codec_in_mode:=ros codec_in_format:=rgb8 codec_out_mode:=ros codec_sub_topic:=/image codec_pub_topic:=/image_mjpeg -
Web 端查看 USB 摄像头图像,另起一个终端:
- Foxy
- Humble
- Jazzy
# 配置tros.b环境
source /opt/tros/setup.bash# 配置tros.b环境
source /opt/tros/humble/setup.bash# 配置tros.b环境
source /opt/tros/jazzy/setup.bash- Humble
# 配置tros.b环境
source /opt/tros/humble/setup.bash- Jazzy
# 配置tros.b环境
source /opt/tros/jazzy/setup.bash# 启动websocket
ros2 launch websocket websocket.launch.py websocket_image_topic:=/image_mjpeg websocket_only_show_image:=true -
PC 打开浏览器(chrome/firefox/edge)输入
http://IP:8000(IP 为 RDK IP 地址),点击左上方 Web 端展示即可查看 USB 摄像头实时画面