本文介绍了在Linux上使用OpenCV捕获多个网络摄像头(uvcvideo)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu 11.10上使用OpenCV 2.1同时从3个Logitech Webcam Pro 900设备流式传输图像. uvcvideo驱动程序已为此加载.

捕获两个设备可以正常工作,但是对于三个设备,我遇到了第三个设备的空间不足错误:

libv4l2: error turning on stream: No space left on device

我似乎遇到了这个问题: http://renoirsrants.blogspot.com.au/2011/07/multiple- cybers-on-zoneminder.html ,而我试图做怪胎= 128(或几乎任何其他的2的幂的值)把戏,但无济于事.我还尝试了另一台具有两个USB 2.0集线器的计算机,并将两个摄像头连接到一个,将第三个摄像头连接到第二个,这导致了同样的问题.我大致初始化如下(使用N台摄像机,因此实际上将结果放入STL向量中):

cv::VideoCapture cap0(0); //(0,1,2..)

并尝试以

的形式捕获所有摄像机

cap0.retrieve(frame0);

这对于N = 2台摄像机很好用.当我将N设置为3时,将打开第三个窗口,但没有图像出现,并且控制台被垃圾邮件充满V4L2错误.同样,当我将N设置为2并尝试打开"Cheese"(简单的网络摄像头捕获应用程序)中的第三个摄像头时,这也不起作用.

现在变得很重要,但是:在启动guvcview的三个实例之后,我能够一次查看三个摄像机(在帧频或相关方面没有问题),因此它似乎不是硬件问题.我认为应该设置一些属性,但是我不确定那是什么.我已经研究了MJPEG(这些相机似乎支持),但是没有成功设置此属性,或者如果我从OpenCV启动它们,则无法检测到它们以哪种模式运行(yuyv?).

有想法吗?

解决方案

我也遇到了这个问题,并且有一个解决方案,允许我使用mjpeg压缩捕获2个640x480的摄像机.我使用的是广告素材"Live Cam Sync HD VF0770",它错误地报告了其带宽要求. quirks = 128修复程序适用于320x240未压缩的视频.但是对于压缩(mjpg)格式,该quirks = 128不起作用(对于压缩格式不起作用).

要解决此问题,我修改了uvc驱动程序,如下所示:

下载内核源代码

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.

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模块:

make

删除旧模块并插入新模块:

sudo rmmod uvcvideo
sudo insmod ./aauvcvideo.ko quirks=128

在2个不同的窗口中通过压缩运行gucview两次以进行测试

guvcview --device=/dev/video1 --format=mjpg --size=640x480
guvcview --device=/dev/video2 --format=mjpg --size=640x480

祝你好运!-橡子

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

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);

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.

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.

Thoughts?

解决方案

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).

To fix this I modified the uvc driver as follows:

download the kernel sources

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

copy uvc dir:

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 .

modify 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

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;
      }

build the aauvcvideo module:

make

remove old module and insert new one:

sudo rmmod uvcvideo
sudo insmod ./aauvcvideo.ko quirks=128

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

Good luck!-Acorn

这篇关于在Linux上使用OpenCV捕获多个网络摄像头(uvcvideo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:31