在 Linux 上使用 OpenCV 捕获多个网络摄像头 (uvcvideo) [英] Capturing multiple webcams (uvcvideo) with OpenCV on Linux
问题描述
我正在尝试在 Ubuntu 11.10 上使用 OpenCV 2.1 同时流式传输来自 3 个 Logitech Webcam Pro 900 设备的图像.为这些加载了 uvcvideo 驱动程序.
I am trying to simultaneously stream the images from 3 Logitech Webcam Pro 900 devices using OpenCV 2.1 on Ubuntu 11.10. The uvcvideo driver gets loaded for these.
捕获两个设备工作正常,但是我遇到了第三个空间不足的错误:
Capturing two devices works fine, however with three I run into the out of space error for the third:
libv4l2: error turning on stream: No space left on device
我似乎遇到了这个问题:http://renoirsrants.blogspot.com.au/2011/07/multiple-webcams-on-zoneminder.html 和我试图做 quirks=128(或几乎任何其他的二次幂值)技巧,但无济于事.我还尝试了另一台带有两个 USB 2.0 集线器的机器,并将两个摄像头连接到一个,第三个摄像头连接到第二个,这导致了同样的问题.我大致初始化如下(使用 N 个摄像头,所以结果实际上被放入一个 STL 向量中):
I seem to be running into this issue: http://renoirsrants.blogspot.com.au/2011/07/multiple-webcams-on-zoneminder.html and I have attempted to do the quirks=128 (or pretty much any other power-of-two value) trick but to no avail. I also tried on another machine with two USB 2.0 hubs and connecting two cameras to one and the third camera to the second, which resulted into the same problem. I am initializing roughly as follows (using N cameras so the result is actually put into an STL vector):
cv::VideoCapture cap0(0); //(0,1,2..)
并尝试将所有摄像头循环捕获为
and attempting to capture all the cameras in a loop as
cap0.retrieve(frame0);
这适用于 N=2 的摄像机.当我设置 N=3 时,第三个窗口打开但没有图像出现,并且控制台充满了 V4L2 错误.同样,当我设置 N=2 并尝试在 Cheese(简单的网络摄像头捕获应用程序)中打开第三个摄像头时,这也不起作用.
This works fine for N=2 cameras. When I set N=3 the third window opens but no image appears and the console is spammed full of V4L2 errors. Similarly, when I set N=2, and attempt to open the third camera in say Cheese (simple webcam capture application), this doesn't work either.
现在大了,但是:通过启动三个实例尝试 guvcview 后,我能够一次查看三个摄像头(在帧速率或相关方面没有问题),所以它似乎不是硬件问题.我想我应该设置一些属性,但我不确定那是什么.我已经研究过 MJPEG(这些相机似乎支持),但没有成功设置此属性,或者如果我从 OpenCV 启动它们,则无法检测它们正在运行的模式(yuyv?).
Now comes the big but: After trying guvcview by starting three instances of that, I was able to view three cameras at once (with no problems in terms of frame rate or related), so it does not seem to be a hardware issue. I figure there is some property that I should set, but I'm not sure what that is. I have looked into MJPEG (which these cameras seem to support), but haven't succeeded into setting this property, or detect in which mode (yuyv?) they are running if I start them from OpenCV.
想法?
推荐答案
我也遇到了这个问题,并且有一个解决方案可以让我使用 mjpeg 压缩以 640x480 捕获 2 个摄像头.我正在使用 Creative Live Cam Sync HD VF0770",它错误地报告了其带宽要求.quirks=128 修复适用于 320x240 未压缩视频.但是对于压缩 (mjpg) 格式, quirks=128 不起作用(它对压缩格式不起作用).
I had this problem too and have a solution that lets me capture 2 cameras at 640x480 with mjpeg compression. I am using a Creative "Live Cam Sync HD VF0770" which incorrectly reports its bandwidth requirements. The quirks=128 fix works for 320x240 uncompressed video. But for compressed (mjpg) format the quirks=128 does not work (it does nothing for compressed formats).
为了解决这个问题,我修改了 uvc 驱动程序如下:
To fix this I modified the uvc driver as follows:
下载内核源码
mkdir -p ~/Software/kernel-git
cd ~/Software/kernel-git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git checkout v3.2
# NOTE: `uname -r` shows me my current kernel is 3.2.0-60-generic
# For a different kernel use a different tag
复制uvc目录:
mkdir -p ~/Software/uvcvideo_driver
cd ~/Software/uvcvideo_driver
#cp -a ~/Software/kernel-git/linux/drivers/media/usb/uvc .
cp ~/Software/kernel-git/linux/drivers/media/video/uvc .
修改Makefile
cd ~/Software/uvcvideo_driver/uvc
vi Makefile
obj-m += aauvcvideo.o
aauvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o
uvc_status.o uvc_isight.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
压缩时强制带宽为 0x400.
Force bandwith to 0x400 when compressed.
cd ~/Software/uvcvideo_driver/uvc
vw uvc_video.c
Find the uvc_fixup_video_ctrl() function. At the end of the function add:
if (format->flags & UVC_FMT_FLAG_COMPRESSED) {
ctrl->dwMaxPayloadTransferSize = 0x400;
}
构建 aauvcvideo 模块:
build the aauvcvideo module:
make
删除旧模块并插入新模块:
remove old module and insert new one:
sudo rmmod uvcvideo
sudo insmod ./aauvcvideo.ko quirks=128
在 2 个不同的窗口中压缩运行两次 gucview 进行测试
run gucview twice with compression in 2 different windows to test
guvcview --device=/dev/video1 --format=mjpg --size=640x480
guvcview --device=/dev/video2 --format=mjpg --size=640x480
祝你好运!-橡子
这篇关于在 Linux 上使用 OpenCV 捕获多个网络摄像头 (uvcvideo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!