前言
usb_cam功能包簡(jiǎn)介
為了豐富機(jī)器人與外界的交互方式,已經(jīng)增加了與機(jī)器人的語(yǔ)音交互方式,不僅使機(jī)器人能夠說(shuō)話發(fā)聲,還能聽(tīng)懂我們說(shuō)的話,但是如果只有語(yǔ)音交互的話機(jī)器人就是一個(gè)盲人,無(wú)法看到這個(gè)色彩斑斕的大千世界,因此我們就需要為機(jī)器人增加視覺(jué)識(shí)別功能。
現(xiàn)在市面上最常見(jiàn)的還是USB攝像頭,物美價(jià)廉,要想使USB攝像頭在ROS下正常工作,我們就需要一個(gè)軟件包來(lái)支持,現(xiàn)在ROS下最常用的usb攝像頭軟件包就是usb_cam了,簡(jiǎn)單理解該軟件包就是V4L(Video for Linux)USB攝像頭驅(qū)動(dòng)在ROS在的一個(gè)移植版本。
截止到目前為止該軟件包在indigo和jade版本上還處于維護(hù)狀態(tài),對(duì)于kinetic版本及其以上還未有維護(hù),當(dāng)然雖然沒(méi)有維護(hù)但是在kinetic版本上也可以工作。
usb_cam 功能包下載與編譯
系統(tǒng)環(huán)境:ubuntu20.04
ROS版本:noetic
usb_cam功能包可以通過(guò)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
接收對(duì)象中: 100% (2232/2232), 843.71 KiB | 306.00 KiB/s, 完成.
處理 delta 中: 100% (1033/1033), 完成.
拷貝到自己的ROS工作空間進(jìn)行編譯
catkin_make
編譯報(bào)錯(cuò):
— 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)
原因就是在usb_cam功能包的CMakeLists.txt的第10行是:
pkg_check_modules(video4linux libv4l2 REQUIRED)
系統(tǒng)中沒(méi)有找到這個(gè)包,所以報(bào)錯(cuò)了。
sudo apt-get install libv4l2-dev
出現(xiàn)無(wú)法定位軟件包,則需要更換鏡像源
我換了源也不行,可能換源沒(méi)有成功
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,耗時(shí) 1秒 (221 kB/s)
正在選中未選擇的軟件包 libv4l2rds0:amd64。
(正在讀取數(shù)據(jù)庫(kù) … 系統(tǒng)當(dāng)前共安裝有 361571 個(gè)文件和目錄。)
準(zhǔn)備解壓 …/libv4l2rds0_1.18.0-2build1_amd64.deb …
正在解壓 libv4l2rds0:amd64 (1.18.0-2build1) …
正在選中未選擇的軟件包 libv4l-dev:amd64。
準(zhǔn)備解壓 …/libv4l-dev_1.18.0-2build1_amd64.deb …
正在解壓 libv4l-dev:amd64 (1.18.0-2build1) …
正在設(shè)置 libv4l2rds0:amd64 (1.18.0-2build1) …
正在設(shè)置 libv4l-dev:amd64 (1.18.0-2build1) …
正在處理用于 libc-bin (2.31-0ubuntu9.9) 的觸發(fā)器 …
再次編譯
catkin_make
順利成功
攝像頭選擇
攝像頭要選擇:
?usb 接口
?支持免驅(qū)協(xié)議:USB Video Class (UVC)
?支持的操作系統(tǒng):Linux with UVC (above linux-2.6)
連接攝像頭
首先先通過(guò) 下面指令看下本地是否有攝像頭,有幾個(gè)
ls /dev/video*
所以再連接攝像頭后,會(huì)掛載到 /dev/video4下面
修改usb_cam功能包下面的config文件夾下的 usb_cam.yml文件中的
video_device: /dev/video0
改為
video_device: /dev/video4
啟動(dòng)功能包
roslaunch usb_cam test_img_view.launch
實(shí)際場(chǎng)景:
采集到的攝像頭圖像:
查看下當(dāng)前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
可配置參數(shù)
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
# 改成自己設(shè)備的掛載位置
video_device: /dev/video4 # Device driver's entrypoint
# 根據(jù)自己攝像頭選擇
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)
# - 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
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
# 發(fā)布topic中的frame_id
camera_frame_id: head_camera # Frame ID used to generate coordinate transformations
# 發(fā)布的話題名稱(chēng)
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)
# 根據(jù)相機(jī)的參數(shù)設(shè)置圖像的寬、高
image_width: 640 # Frame dimensions, should be supported by camera hardware
image_height: 480
# 發(fā)布頻率
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
# 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
+關(guān)注
關(guān)注
60文章
7773瀏覽量
262389 -
相機(jī)圖像
+關(guān)注
關(guān)注
0文章
7瀏覽量
6003 -
ROS
+關(guān)注
關(guān)注
1文章
276瀏覽量
16884
原文標(biāo)題:ROS系統(tǒng)讀取USB相機(jī)圖像數(shù)據(jù)
文章出處:【微信號(hào):vision263com,微信公眾號(hào):新機(jī)器視覺(jué)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論