OpenCV VideoCapture设备索引/设备编号 [英] OpenCV VideoCapture device index / device number

查看:695
本文介绍了OpenCV VideoCapture设备索引/设备编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python环境(在Windows 10上),该环境使用OpenCV VideoCapture类连接到多个USB摄像机.

I have a python environment (on Windows 10) that uses OpenCV VideoCapture class to connect to multiple usb cameras.

据我所知,除了VideoCapture类构造函数/open方法中的device参数外,无法识别OpenCV中的特定摄像机.

As far as I know, there is no way to identify a specific camera in OpenCV other than the device parameter in the VideoCapture class constructor / open method.

问题在于设备参数会根据实际连接的相机数量和USB端口的数量而变化.

The problem is that the device parameter changes depending on how many cameras are actually connected and to which usb ports.

我希望能够识别特定的摄像机并找到其设备索引"或摄像机索引",无论连接了多少个摄像机以及哪些USB端口.

I want to be able to identify a specific camera and find its "device index" or "camera index" no matter how many cameras are connected and to which usb ports.

有人可以建议一种实现该功能的方法吗?最好使用python代码,但C ++也可以.

Can somebody please suggest a way to achieve that functionality? python code is preferable but C++ will also do.

推荐答案

据我所知,openCV枚举设备并将其索引用作相机索引. 但是枚举的方式在后端之间可能有所不同. 无论如何,如果您可以像OpenCV一样枚举设备,则可以匹配设备的索引,并且其信息取决于您的代码.

As far as I know, openCV enumerates devices and uses the index of it as a camera index. But the way it enumerates can differ among backends. Anyway, if you can enumerate devices as OpenCV do, you can match the index of the device and its information depend on your code.

因此,在Windows环境中,可以将MSMF或DSHOW用作后端.如果您使用MSMF作为后端,我做了一个简单的函数来列出设备并将其名称与其索引匹配. 此处: https://github.com/pvys/CV-camera-finder .

So, In Windows environment, you can use MSMF or DSHOW as a backend. If you are using MSMF as a backend, I made a simple function to list devices and match its name to its index. Here: https://github.com/pvys/CV-camera-finder.

如果您使用DSHOW作为背景,这是一篇不错的文章:

If you are using DSHOW as a background, here's a nice article: https://www.codeproject.com/Articles/1274094/Capturing-Images-from-Camera-using-Python-and-Dire

这篇关于OpenCV VideoCapture设备索引/设备编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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