ros2 usb camera的发布与web可视化查看相机图像
本文中使用的ros2 humble Ubuntu22 .
usb camera 支持uvc 。
程序为 ros2
https://gitlab.com/boldhearts/ros2_v4l2_camera#usage-1
该程序支持大部分的 uvc usb camera
ros2 直接安装
sudo apt-get install ros-humble-v4l2-camera
ros2 run v4l2_camera v4l2_camera_node
orangepi@orangepi5:~/ros2_ws/src$ ros2 run v4l2_camera v4l2_camera_node
[INFO] [1715932445.388780316] [v4l2_camera]: Driver: uvcvideo
[INFO] [1715932445.389265058] [v4l2_camera]: Version: 330350
[INFO] [1715932445.389386098] [v4l2_camera]: Device: Rmoncam A2 720P: RMONCAM A2 72
[INFO] [1715932445.389478555] [v4l2_camera]: Location: usb-xhci-hcd.9.auto-1
[INFO] [1715932445.389560220] [v4l2_camera]: Capabilities:
[INFO] [1715932445.389639260] [v4l2_camera]: Read/write: NO
[INFO] [1715932445.389716259] [v4l2_camera]: Streaming: YES
[INFO] [1715932445.389833799] [v4l2_camera]: Current pixel format: YUYV @ 1280x800
[INFO] [1715932445.390124002] [v4l2_camera]: Available pixel formats:
[INFO] [1715932445.390221709] [v4l2_camera]: MJPG - Motion-JPEG
[INFO] [1715932445.390284125] [v4l2_camera]: YUYV - YUYV 4:2:2
[INFO] [1715932445.390354707] [v4l2_camera]: Available controls:
[INFO] [1715932445.391935222] [v4l2_camera]: Brightness (1) = 0
[INFO] [1715932445.393452739] [v4l2_camera]: Contrast (1) = 32
[INFO] [1715932445.395049587] [v4l2_camera]: Saturation (1) = 64
[INFO] [1715932445.396837474] [v4l2_camera]: Hue (1) = 0
[INFO] [1715932445.397065845] [v4l2_camera]: White Balance Temperature, Auto (2) = 1
[INFO] [1715932445.398656694] [v4l2_camera]: Gamma (1) = 300
[INFO] [1715932445.399952256] [v4l2_camera]: Gain (1) = 64
[INFO] [1715932445.401052696] [v4l2_camera]: Power Line Frequency (3) = 1
[INFO] [1715932445.402432840] [v4l2_camera]: White Balance Temperature (1) = 4600 [inactive]
[INFO] [1715932445.403740651] [v4l2_camera]: Sharpness (1) = 50
[INFO] [1715932445.405328458] [v4l2_camera]: Backlight Compensation (1) = 0
[INFO] [1715932445.405574329] [v4l2_camera]: Exposure, Auto (3) = 3
[INFO] [1715932445.407142011] [v4l2_camera]: Exposure (Absolute) (1) = 166 [inactive]
[INFO] [1715932445.408599154] [v4l2_camera]: Exposure, Auto Priority (2) = 1
[INFO] [1715932445.412213719] [v4l2_camera]: Requesting format: 640x480 YUYV
[INFO] [1715932445.422154554] [v4l2_camera]: Success
[INFO] [1715932445.423676445] [v4l2_camera]: Succesfully set value for control Exposure, Auto Priority to 0
[INFO] [1715932445.425627080] [v4l2_camera]: Starting camera
[WARN] [1715932445.691544207] [v4l2_camera]: Image encoding not the same as requested output, performing possibly slow conversion: yuv422_yuy2 => rgb8
[INFO] [1715932445.717555483] [v4l2_camera]: using default calibration URL
[INFO] [1715932445.717906936] [v4l2_camera]: camera calibration URL: file:///home/orangepi/.ros/camera_info/rmoncam_a2_720p:_rmoncam__a2_72.yaml
[ERROR] [1715932445.718424635] [camera_calibration_parsers]: Unable to open camera calibration file [/home/orangepi/.ros/camera_info/rmoncam_a2_720p:_
另外起一个终端查看topic 信息
orangepi@orangepi5:~$ ros2 topic list
/camera_info
/image_raw
/parameter_events
/rosout
orangepi@orangepi5:~$ ros2 topic echo /image_raw --no-ar
header:
stamp:
sec: 1715932535
nanosec: 685604250
frame_id: camera
height: 480
width: 640
encoding: rgb8
is_bigendian: 0
step: 1920
data: '<sequence type: uint8, length: 921600>'
---
header:
stamp:
sec: 1715932535
nanosec: 717800799
frame_id: camera
height: 480
width: 640
encoding: rgb8
is_bigendian: 0
step: 1920
data: '<sequence type: uint8, length: 921600>'
---
image_raw是原始图像的输出。符合格式
/image_raw - sensor_msgs/Image
此包用于发布图像和使可以压缩。但是,默认情况下,它仅支持原始
传输,需要额外的插件才能启用压缩。这些需要单独安装,要么克隆建筑物,要么从中克隆
source 或安装现成的软件包:image_transport
sudo apt-get install ros-humble-image-transport-plugins
安装后,它们将被驱动程序自动使用
将提供其他主题,包括 ./image_raw/compressed
ros2发行版可以看这个
https://github.com/ros-drivers/usb_cam/tree/ros2
接着下载 ros2 web_video_server-ros2
git clone https://github.com/horo2016/web_video_server-ros2.git
colcon build
Consolidate compiler generated dependencies of target web_video_server
[ 9%] Building CXX object CMakeFiles/web_video_server.dir/src/image_streamer.cpp.o
[ 27%] Building CXX object CMakeFiles/web_video_server.dir/src/jpeg_streamers.cpp.o
[ 27%] Building CXX object CMakeFiles/web_video_server.dir/src/png_streamers.cpp.o
[ 36%] Building CXX object CMakeFiles/web_video_server.dir/src/ros_compressed_streamer.cpp.o
[ 45%] Linking CXX executable web_video_server
[100%] Built target web_video_server
-- Install configuration: ""
-- Installing: /home/orangepi/ros2_ws/install/web_video_server/lib/web_video_server/web_video_server
-- Set runtime path of "/home/orangepi/ros2_ws/install/web_video_server/lib/web_video_server/web_video_server" to ""
-- Installing: /home/orangepi/ros2_ws/install/web_video_server/include/web_video_server
-- Installing: /home/orangepi/ros2_ws/install/web_video_server/include/web_video_server/vp8_
-- Installing: /home/orangepi/ros2_ws/install/web_video_server/share/web_video_server/environment/ament_prefix_path.sh
....
Finished <<< web_video_server [24.6s]
接着在soure
soure install/setup.bash
在启动v4l2节点基础上
ros2 run v4l2_camera v4l2_camera_node
在新开终端启动web_video_server
orangepi@orangepi5:~$ ros2 run web_video_server web_video_server
[INFO] [1715939457.393743263] [web_video_server]: Waiting For connections on 0.0.0.0:8080
topic_type: sensor_msgs/msg/CameraInfo
topic_type: sensor_msgs/msg/Image
topic_type: rcl_interfaces/msg/ParameterEvent
topic_type: rcl_interfaces/msg/Log
电脑浏览器输入终端IP地址:8080
http://192.168.3.19:8080/