问题
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