0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

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

新机器视觉 来源:新机器视觉 2023-10-29 11:26 次阅读

前言

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_ca

下载完成后提示:

正克隆到 ‘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), 完成.

eb8072ee-7568-11ee-939d-92fbcf53809c.png

拷贝到自己的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)

eb853eb4-7568-11ee-939d-92fbcf53809c.png

原因就是在usb_cam功能包的CMakeLists.txt的第10行是:

pkg_check_modules(video4linux libv4l2 REQUIRED)

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

sudo apt-get install libv4l2-dev

出现无法定位软件包,则需要更换镜像源

eb8e1700-7568-11ee-939d-92fbcf53809c.png

我换了源也不行,可能换源没有成功

sudo apt-get install libv4l-dev

成功了

获取:1http://mirrors.aliyun.com/ubuntufocal/main amd64 libv4l2rds0 amd64 1.18.0-2build1 [15.8 kB]
获取:2http://mirrors.aliyun.com/ubuntufocal/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

顺利成功

eb9bce4a-7568-11ee-939d-92fbcf53809c.png

摄像头选择

摄像头要选择:

•usb 接口

•支持免驱协议:USB Video Class (UVC)

•支持的操作系统:Linux with UVC (above linux-2.6)

连接摄像头

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

ls /dev/video*

eb9fac68-7568-11ee-939d-92fbcf53809c.png

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

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

video_device: /dev/video0

改为

video_device: /dev/video4

启动功能包

roslaunch usb_cam test_img_view.launch

实际场景:

eba88cca-7568-11ee-939d-92fbcf53809c.png

采集到的摄像头图像:

ebaccbaa-7568-11ee-939d-92fbcf53809c.png

查看下当前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

可配置参数

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_40_.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 -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!


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • usb
    usb
    +关注

    关注

    59

    文章

    7432

    浏览量

    258168
  • 相机图像
    +关注

    关注

    0

    文章

    7

    浏览量

    5990
  • ROS
    ROS
    +关注

    关注

    1

    文章

    271

    浏览量

    16681

原文标题:ROS系统读取USB相机图像数据

文章出处:【微信号:vision263com,微信公众号:新机器视觉】欢迎添加关注!文章转载请注明出处。

收藏 人收藏

    评论

    相关推荐

    labview的USB通信数据读取的问题

    正在做一个数据采集系统,通信选择USB通信,上位机使用labiew编写,我想问一下,因为下位数据采集时需要一定的时间,怎么让上位机在判断到采集数据
    发表于 03-23 12:35

    USB3.0工业相机模块 全局曝光130万像素210帧 工业相机模块

    图像数据处理更轻松。QIKE系列USB3.0工业相机模块命名规则: QIKE系列USB3.0工业相机
    发表于 10-19 10:33

    USB3.0工业相机模块 全局曝光130万像素210帧 工业相机模块

    逼真,图像数据处理更轻松。QIKE系列USB3.0工业相机模块命名规则: QIKE系列USB3.0工业
    发表于 10-23 10:38

    USB3.0工业相机模块 全局曝光130万像素210帧 工业相机

    逼真,图像数据处理更轻松。QIKE系列USB3.0工业相机模块命名规则: QIKE系列USB3.0工业
    发表于 01-08 14:25

    USB3.0工业相机模块 全局曝光30万像素 810帧 USB3.0相机模块

    逼真,图像数据处理更轻松。QIKE系列USB3.0工业相机模块命名规则: QIKE系列USB3.0工业
    发表于 01-24 13:49

    labview实现相机读取教程分析

    。  labview实现相机读取  一、程序功能  1.通过选择相机实现电脑摄像头或CCD连续图像采集。 2.控制图像采集时间。  3.显示
    发表于 05-03 08:00

    学习图像采集入门篇—labview实现USB相机图像采集

    操作说明: 1.选择相机名称 2.设置采集时间 3.运行VI 相机名字:通过下拉菜单选择相机,包括电脑摄像头和USB接口的CCD设备采集速率。  采集速率:实时显示采集
    发表于 06-13 08:00

    基于采用FPGA控制MV-D1024E系列相机图像采集系统设计

    ) 以其可靠性好、集成度高、功耗低和运算速度高等优势,在高速实时图像采集系统得到广泛应用。这里采用FPGA控制MV-D1024E系列相机数据接口,实现了脱离PC机的
    发表于 07-02 08:11

    如何去搭建一个基于ROS系统的平衡车呢

    OPENCR硬件是怎样通过USB虚拟串口的方式和ROS系统进行通信呢?如何去搭建一个基于ROS系统的平衡车呢?
    发表于 11-08 06:57

    esp32s2的usb如何读取USB相机

    在bilibili看到了esp32s2的usb读取usb相机画面的视频,我们现在有个项目,想这么做。但是usb这块要怎么整没什么头绪,是
    发表于 02-20 08:45

    基于FPGA与USB的CMOS图像获取与采集系统设计

    实现了基于FPGA与USB的CMOS图像获取与采集系统的设计。介绍了成像系统的结构、CMOS图像获取时序的VHDL程序实现、包含FPGA控制
    发表于 09-22 16:53 23次下载

    多光谱CCD相机图像采集系统的设计_李爱玲

    多光谱CCD相机图像采集系统的设计_李爱玲
    发表于 03-19 11:29 3次下载

    如何使用FPGA和MV-D1024E相机实现图像采集系统的设计

    USB接口,利用PC机作为参数輸入和显示界面,完成一个从图像采集到存储、显示的高帧频图像采集系统的设计。该系统可靠性妤、集成度高、功耗低,
    发表于 01-29 16:00 6次下载
    如何使用FPGA和MV-D1024E<b class='flag-5'>相机</b>实现<b class='flag-5'>图像</b>采集<b class='flag-5'>系统</b>的设计

    3D相机点云数据“如何读取

    Halcon|读取3D相机点云数据 最近发现很多小伙伴在使用Halcon处理3D工业相机扫描结果的时候遇到了“如何读取”的问题。一般的3D工
    的头像 发表于 07-12 10:28 925次阅读
    3D<b class='flag-5'>相机</b>点云<b class='flag-5'>数据</b>“如何<b class='flag-5'>读取</b>”

    ROS主控读取stm32发送的数据

    ROS主控读取stm32发送的数据 之后便可以通过 Stm32_Serial .read (Receive_Data_Pr,sizeof(Receive_Data_Pr)); read函数读取
    的头像 发表于 11-26 17:49 765次阅读