Ask Your Question

Revision history [back]

How to identify multiple cameras

Hello,

I use two cameras at same computer, to capture photos and videos. Each camera is responsible for unique tasks.

I don't have problems to open parallel cameras and capture videos or pictures. For now, I used just index number to open each device:

cv::VideoCapture cap_foo(0);
cv::VideoCapture cap_foo(1);

No problem at this point, all works fine.

However, at first time I don't know which index is from which camera. I need capture a simple picture to discover the position. (LEDs from device aren't available)

The index is the same sequence ever. (good)

Although, some times I get some hardware error from a camera (normally at index 0), as result, OpenCV provide just index 0 to open. So, at this point I need look the video capture to identify which camera is working. (bad)

I tried use the "Device Path" as an unique id for each camera:

cv::VideoCapture cap_first("\\\\?\\usb#vid_045e&pid_074a&mi_00#7&243504bc&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global");
cv::VideoCapture cap_secon("\\\\?\\usb#vid_1871&pid_0f01&mi_00#8&2aa65eb9&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global");

However, I get just an error message: warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)

Then, I need a mechanism that informs which camera is connected in which index. How is possible? (Direct Show is an option)