Linux 从网络摄像头抓取图像以与 OpenCV 一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5033253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:53:49  来源:igfitidea点击:

Grabbing Images from a Webcam to be used with OpenCV

linuximage-processingopencv

提问by Hamza Yerlikaya

This is a follow up to my previous question,

这是对我上一个问题的跟进,

OpenCV PS 3 Eye

OpenCV PS 3 眼

Can someone suggest a library that would allow me grab frames from camera without too much fuss (like video videoinput lib for windows) and pass them to opencv within my application?

有人可以建议一个库,它可以让我从相机中抓取帧而不必大惊小怪(例如 windows 的视频视频输入库)并将它们传递给我的应用程序中的 opencv 吗?

回答by ejb

I had a parallel problem using a completely different webcam: worked well in cheese/etc, v4l-infoshowed proper setup, but openCV would fail with:

我在使用完全不同的网络摄像头时遇到了一个并行问题:在 cheese/etc 中运行良好,v4l-info显示了正确的设置,但 openCV 会失败:

HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV Unable to stop the stream.: Bad file descriptor

HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV Unable to stop the stream.: Bad file descriptor

After much flailing I found that at least one guyhad similar problems with webcams in various applications.

经过一番折腾,我发现至少有一个人在各种应用程序中遇到了类似的网络摄像头问题。

In blind faith I promptly punched in export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.soand ?poof? it worked.

我盲目地立即打了进来,export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so然后??有效。

The openCV v4l2 interface is not as robust as the v4l implementation and the export is a quick workaround(openCV appears to revert to v4l).

openCV v4l2 接口不像 v4l 实现那样健壮,导出是一种快速的解决方法(openCV 似乎恢复到 v4l)。

With a quick browse of opencv/modules/highgui/src/cap_v4l.cppit would appear as though openCV would like to use v4l2.

快速浏览opencv/modules/highgui/src/cap_v4l.cpp它看起来好像 openCV 想使用 v4l2。

I'm running Ubuntu Lucid 2.6.32-28-generic x86_64, libv4l-0 v0.6.4-1ubuntu1 with openCV pulled from the HEAD of the repo a few days ago.

我正在运行 Ubuntu Lucid 2.6.32-28-generic x86_64, libv4l-0 v0.6.4-1ubuntu1 几天前从 repo 的 HEAD 中提取的 openCV。

In the course of explaining this I've resolved my issue. It turns out that openCV forces the resolution on a v4l2 device to 640x480 by default - and my device had a max 320x240 resolution which caused the fault when testing for the format type in opencv::highgui::cap_v41::try_palette_v4l2. I changed DEFAULT_V4L_WIDTHand, DEFAULT_V4L_HEIGHT.

在解释这一点的过程中,我解决了我的问题。事实证明,默认情况下,openCV 强制 v4l2 设备上的分辨率为 640x480 - 我的设备的最大分辨率为 320x240,这在测试opencv::highgui::cap_v41::try_palette_v4l2. 我更改了DEFAULT_V4L_WIDTHDEFAULT_V4L_HEIGHT