Is there a platform independent way to list video input devices

亡梦爱人 提交于 2021-01-01 06:59:06

问题


Before opening doing a capture by creating a VideoCapture object I want to display a list of available devices to select from. I believe this can be done in Windows using DirectShow and in Linux by checking the /dev/video* entries.

But I am wondering if there is any platform independent way I can get this list?

NOTE. I know I can enumerate the devices using VideoCapture.open and checking isOpen but I want to be able to display a meaningful name also and I don't think VideoCapture gives me that?


回答1:


I understand that available devices means cameras connected to your computer.

  • Firstly, to be able to use VideoCapture with a camera; camera shouldn't have a driver. Generally, VideoCapture is available to use with simple cameras such as webcams, some usb cameras etc.
  • OpenCV doesn't have a property to count or list the available cameras which are connected. You can also check this post.
  • Just for counting cameras, you can also use a brute way like this:

Example:

VideoCapture cap;
    int device_counts = 0;
    while ( true ) {
        if ( !cap.open(device_counts++) ) {
            break;
        }
    }
  • But in my opinion, the best solution is that using a framework to achieve that. For example Qt Creator.


来源:https://stackoverflow.com/questions/61510571/is-there-a-platform-independent-way-to-list-video-input-devices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!