在 OpenCV 方法 VideoCapture.open() 中使用设备名称而不是 ID [英] Using device name instead of ID in OpenCV method VideoCapture.open()

查看:118
本文介绍了在 OpenCV 方法 VideoCapture.open() 中使用设备名称而不是 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 /dev 文件夹中有很多视频设备(例如 video1video2、...、video9)和一个始终指向有效设备的 /dev/video (当然,可以更改).我想用 cv::Videocapture 用 OpenCV 打开 /dev/video 设备,发现只有两种打开方式:

I have a lot of video devices in my /dev folder (e.g. video1, video2, ..., video9) and one /dev/video which is always pointing to the valid device (which, of course, can change). I want to open the /dev/video device with OpenCV using cv::Videocapture and realized that there are only two ways to open it:

VideoCapture::VideoCapture(const string& filename)
VideoCapture::VideoCapture(int device)

第一个打开一个文件,第二个打开/dev/video[device].

The first one opens a file and the second one opens /dev/video[device].

有没有办法像 cap = cv::VideoCapture("/dev/video");?

推荐答案

使用当前的 OpenCV 3.2.0,您可以像这样创建新的捕获:

with current OpenCV 3.2.0 you can create a new capture like this:

cv::VideoCapture cap("/dev/video20", cv::CAP_V4L);

它是额外的构造函数之一:

its one of the additional constructors:

VideoCapture (const String &filename, int apiPreference)
使用 API Preference 打开视频文件或捕获设备或 IP 视频流以进行视频捕获.

VideoCapture (const String &filename, int apiPreference)
Open video file or a capturing device or a IP video stream for video capturing with API Preference.

这也可以通过 open 函数实现:

this is also possible with the open function:

cap.open("/dev/video20", cv::CAP_V4L);

我已经在 Kubuntu 16.10 下使用当前 git master 自行编译的 openCV 成功测试了这一点.

i have tested this successfully under Kubuntu 16.10 with self compiled openCV from current git master.

这篇关于在 OpenCV 方法 VideoCapture.open() 中使用设备名称而不是 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆