Using device name instead of ID in OpenCV method VideoCapture.open()(在 OpenCV 方法 VideoCapture.open() 中使用设备名称而不是 ID)
问题描述
我的 /dev 文件夹中有很多视频设备(例如 video1、video2、...、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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 OpenCV 方法 VideoCapture.open() 中使用设备名称而不是 ID
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
