ROS系统读取USB相机图像数据

这篇具有很好参考价值的文章主要介绍了ROS系统读取USB相机图像数据。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

usb_cam功能包简介
为了丰富机器人与外界的交互方式,已经增加了与机器人的语音交互方式,不仅使机器人能够说话发声,还能听懂我们说的话,但是如果只有语音交互的话机器人就是一个盲人,无法看到这个色彩斑斓的大千世界,因此我们就需要为机器人增加视觉识别功能。现在市面上最常见的还是USB摄像头,物美价廉,要想使USB摄像头在ROS下正常工作,我们就需要一个软件包来支持,现在ROS下最常用的usb摄像头软件包就是usb_cam了,简单理解该软件包就是V4L(Video for Linux)USB摄像头驱动在ROS在的一个移植版本。截止到目前为止该软件包在indigo和jade版本上还处于维护状态,对于kinetic版本及其以上还未有维护,当然虽然没有维护但是在kinetic版本上也可以工作。

usb_cam 功能包下载与编译

系统环境:ubuntu20.04
ROS版本:noetic

usb_cam功能包可以通过github下载

git clone  https://github.com/bosch-ros-pkg/usb_cam.git usb_cam

下载完成后提示:

正克隆到 ‘usb_cam’…
remote: Enumerating objects: 2232, done.
remote: Counting objects: 100% (2232/2232), done.
remote: Compressing objects: 100% (1015/1015), done.
remote: Total 2232 (delta 1033), reused 2082 (delta 988), pack-reused 0
接收对象中: 100% (2232/2232), 843.71 KiB | 306.00 KiB/s, 完成.
处理 delta 中: 100% (1033/1033), 完成.

ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据

拷贝到自己的ROS工作空间进行编译

catkin_make

编译报错:

– Checking for module ‘libv4l2’
– No package ‘libv4l2’ found
CMake Error at /usr/share/cmake-3.16/Modules/FindPkgConfig.cmake:463 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPkgConfig.cmake:643 (_pkg_check_modules_internal)
usb_cam/CMakeLists.txt:10 (pkg_check_modules)

ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据
原因就是在usb_cam功能包的CMakeLists.txt的第10行是:

pkg_check_modules(video4linux libv4l2 REQUIRED)

系统中没有找到这个包,所以报错了。

sudo apt-get install libv4l2-dev

出现无法定位软件包,则需要更换镜像源
ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据
我换了源也不行,可能换源没有成功

sudo apt-get install libv4l-dev

成功了

获取:1 http://mirrors.aliyun.com/ubuntu focal/main amd64 libv4l2rds0 amd64 1.18.0-2build1 [15.8 kB]
获取:2 http://mirrors.aliyun.com/ubuntu focal/main amd64 libv4l-dev amd64 1.18.0-2build1 [108 kB]
已下载 124 kB,耗时 1秒 (221 kB/s)
正在选中未选择的软件包 libv4l2rds0:amd64。
(正在读取数据库 … 系统当前共安装有 361571 个文件和目录。)
准备解压 …/libv4l2rds0_1.18.0-2build1_amd64.deb …
正在解压 libv4l2rds0:amd64 (1.18.0-2build1) …
正在选中未选择的软件包 libv4l-dev:amd64。
准备解压 …/libv4l-dev_1.18.0-2build1_amd64.deb …
正在解压 libv4l-dev:amd64 (1.18.0-2build1) …
正在设置 libv4l2rds0:amd64 (1.18.0-2build1) …
正在设置 libv4l-dev:amd64 (1.18.0-2build1) …
正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 …

再次编译

catkin_make

顺利成功
ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据

摄像头选择

摄像头要选择:

  • usb 接口
  • 支持免驱协议:USB Video Class (UVC)
  • 支持的操作系统:Linux with UVC (above linux-2.6)

连接摄像头

首先先通过 下面指令看下本地是否有摄像头,有几个

ls /dev/video*

ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据
这代表有两个摄像头(一个摄像头出两个/dev/video*)

所以再连接摄像头后,会挂载到 /dev/video4下面

修改usb_cam功能包下面的config文件夹下的 usb_cam.yml文件中的

video_device: /dev/video0 

改为

video_device: /dev/video4 

启动功能包

roslaunch usb_cam test_img_view.launch

实际场景:
ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据

采集到的摄像头图像:
ros获取摄像头图像并识别内容,ros,ROS,摄像头,相机,usb_cam,图像数据
查看下当前topic

rostopic list

/image_view/output
/image_view/parameter_descriptions
/image_view/parameter_updates
/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

输出频率为30hz

rostopic hz /usb_cam/image_raw/theora
subscribed to [/usb_cam/image_raw/theora]
average rate: 32.730
min: 0.000s max: 0.041s std dev: 0.01037s window: 33
average rate: 31.137
min: 0.000s max: 0.047s std dev: 0.00844s window: 62
average rate: 30.616
min: 0.000s max: 0.047s std dev: 0.00748s window: 92文章来源地址https://www.toymoban.com/news/detail-844716.html

可配置参数

start_service_name: "start_capture" # Defines name suffix for std_srvs::Empty service which restarts suspended streaming
stop_service_name: "stop_capture"   # Defines name suffix for std_srvs::Empty service which suspends camera polling timer

# 改成自己设备的挂载位置
video_device: /dev/video4           # Device driver's entrypoint
# 根据自己摄像头选择
io_method: mmap                     # I/O method
                                    # - read - for devices supporting virtual filesystem or block I/O
                                    # - mmap - for devices with direct libusb memory mapping
                                    # - userptr - for userspace devices supporting userspace pointer exchange
# 图像编码格式                                
pixel_format: yuyv                  # Pixel format for Video4linux device (also selects decoder mode)
                                        # https://wiki.videolan.org/YUV#YUV_4:2:0_.28I420.2FJ420.2FYV12.29
                                        # - yuyv - YUV420
                                        # - yuv - synonym for yuyv
                                        # - uyvy - UVY240
                                        # - yuvmono10 - Monochrome 10-bit pseudo-YUV
                                        # - rgb24 - Linear 8-bit RGB
                                        # - bgr24 - OpenCV-compatible 8-bit BGR
                                        # - grey - Grayscale 8-bit monochrome
                                        # - yu12 - YU-reversed YUV420
                                        # - mjpeg - FFMPEG decoder, MotionJPEG, for compatible hardware
                                        # - h264 - FFMPEG decoder, H.264, for compatible hardware
color_format: yuv422p               # On-chip color representation mode for the input frame encoded by hardware
                                        # - yuv422p - YUV422 - default, compatible with most MJPEG hardware encoders
                                        # - yuv420p - YUV420 - mandatory for H.264 and H.265 hardware encoders
create_suspended: false             # Instructs the node whether to start streaming immediately after launch
                                    # or to wait until the start service will be triggered
full_ffmpeg_log: false              # Allows to suppress warning messages generated by libavcodec, cleans log
camera_name: head_camera            # ROS internal name for the camera, used to generate camera_info message
# 发布topic中的frame_id
camera_frame_id: head_camera        # Frame ID used to generate coordinate transformations
# 发布的话题名称
camera_transport_suffix: image_raw  # Suffix used by image_transport to generate topic names
camera_info_url: ""                 # URI for camera calibration data (likely a YML file obtained from camera_calibration)
# 根据相机的参数设置图像的宽、高
image_width: 640                    # Frame dimensions, should be supported by camera hardware
image_height: 480
# 发布频率
framerate: 30                       # Camera polling frequency, Hz (integer)

# Auxiliary camera parameters provided by libv4l2.
    # Names for these parameters are generated automatically according to the intrinsic control names exported by the
    # camera driver. The node queries camera's kernel controller module to determine the parameters that can be set up
    # via ROS. For these parameters the corresponding ROS parameters with identical names are generated under this
    # namespace.
    # See also the comprehensive node output describing parameter names and feasible values for them to be set up here.
    # It is also possible to have a list of the available control names using v4l2-ctl application from v4l2-util package:
    # v4l2-ctl --device=/dev/video<ID> -L
intrinsic_controls:                 
    focus_auto: true
    exposure_auto_priority: true
    exposure_auto: 3
    white_balance_temperature_auto: true
    power_line_frequency: 1
    ignore: [
        brightness,
        contrast,
        saturation,
        gain,
        sharpness,
        backlight_compensation,
        white_balance_temperature,
        exposure_absolute,
        pan_absolute,
        tilt_absolute,
        focus_absolute,
        zoom_absolute
    ]                               # Use this list to enumerate the control names that should be delisted from the camera setup
                                    # NOTE: the ROS parameters for the V4L controls supported but listed here would be STILL
                                    # generated, but the values WILL NOT BE USED to set up the camera. To affect these controls
                                    # once you want to do that, their names should me REMOVED from this list!


到了这里,关于ROS系统读取USB相机图像数据的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【ROS】usb_cam相机标定

    1. 唠叨两句 当我们要用相机做测量用途时,就需要做相机标定了,不然得到的计算结果会有很大误差,标定的内容包括三部分:内参,外参还有畸变参数。所以标定的过程就是要求得上面这些参数。 以前弄这个事估计挺麻烦,需要做实验和计算才能得到,现在通过ros的开源

    2024年02月08日
    浏览(31)
  • 基于虚拟机安装Ubuntu18.04+ROS的2D相机或电脑自带摄像头的在线标定方法

    硬件 :笔记本电脑自带摄像头或者通过usb接口连接的相机 软件 :虚拟机+ubuntu18.04+ROS1 melodic(针对ubuntu18.04对应的ROS版本) 首先确保在主目录下,创建ROS工程 克隆代码 编译代码 这个地方我报错了 – No package ‘libv4l2’ found CMake Error at /usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:419

    2024年02月02日
    浏览(46)
  • ROS订阅相机图像消息,并将图像保存为视频帧

    需求 需要编写一个Python程序,订阅电脑外接的深度相机发出的视频消息,录制视频并逐帧保存为图片到本地,用于采集制作数据集的图片信息 运行环境 Ubuntu18.04 + ROS Melodic + Python2.7 Python程序 程序解释 这段代码是一个用于ROS(Robot Operating System)环境下的Python程序,用于订阅

    2024年02月13日
    浏览(31)
  • ros来保存图像和保存记录视频的方法---gmsl相机保存视频和图片

    rosrun image_view image_view image:=/myimg_topic这个命令只是用来查看图像的,它并不会保存图像。如果你想要保存图像,你需要使用image_saver节点,并指定保存路径。例如: 下面指令就可以了,可以用 在这个命令中,/path/to/folder/是你想要保存图片的文件夹路径。image%04d.jpg是保存的图

    2024年02月04日
    浏览(27)
  • 十九.在ROS系统基于点云和视觉图像数据融合构建3D点云场景

    一. 背景介绍         现在很多智能导航场景都涉及到激光(毫米波,固态等)雷达和相机视觉信息融合,这里激光雷达一般都是指多线激光雷达,16线,64线,甚至更多线数. 但多线激光雷达动不动数万的价格,让很多技术人员无法尝试.我前面写过一篇使用单线激光雷达和相机视觉融合

    2023年04月08日
    浏览(34)
  • 随手笔记——通过OpenCV获取图像转为ROS图像话题发布(C++版)

    通过OpenCV获取图像转为ROS图像话题发布 注:sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), “bgr8”, image).toImageMsg(); //核心代码

    2024年02月12日
    浏览(25)
  • 【ROS】如何让ROS中节点获取数据 III --参数服务器通信及ros常用工具指令介绍

    Halo,这里是Ppeua。平时主要更新C语言,C++,数据结构算法…感兴趣就关注我吧!你定不会失望。 相较于之前的通信模型,参数服务器是最为简单的。在之前的模型中,ROSMASTER都是扮演一个帮二者连接在一起的桥梁。 而在参数服务器中: ROSMASTER变为了一个存储消息的容器 ,

    2024年02月04日
    浏览(37)
  • ROS学习笔记(五):rosbag与读取图片与点云数据

    录制所有话题: 录制指定话题,设置 bag 包名: 以暂停的方式启动,防止跑掉数据 设置以 0.5 倍速回放,也就是以录制频率的一半回放 如果录制的 bag 很大,我们可以压缩它,默认的压缩格式是 bz2: 你也可以添加 -j 手动指定压缩格式为 bz2: 也可以使用 LZ4 来压缩数据:

    2024年02月13日
    浏览(68)
  • ROS(十一):ubuntu调用摄像头

      在Windows环境下,安装在VMware中及Ubuntu的具体步骤可以看此篇博客:ROS(一):在Windows环境下,安装在VMware中及Ubuntu 在虚拟机中安装VMware Tools的具体步骤可以看此篇博客:ROS(二):在虚拟机中安装VMware Tools Ubuntu与Windows之间的复制粘贴、文件拖拽的具体步骤可以看此篇博客:ROS

    2024年02月07日
    浏览(29)
  • ROS小车——摄像头的使用(3)

    ROS小车的摄像头驱动和图像的查看,以及opencv的使用。 roslaunch robot_vision robot_camera.launch打开摄像头,并用另一个终端打开节点rostopic list发现摄像头 小车没有看图的工具,我们借助虚拟机 使用rqt工具rqt_image_view,然后选择话题列表 一个终端roslaunch robot_vision robot_camera.launch打开

    2024年02月05日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包