I am currently using opencv2.4.8 with three cameras on Win 7 in C++. I understand how to read from a camera through VideoCapture cap etc but I am having trouble identifying which camera is which.

From what I can understand, cap.open(int num) takes in the camera index. In my case, these are 0, 1, & 2.

CAMA = 0
CAMB = 1
CAMC = 2

If however, before starting up the program, cam at index 0 becomes unplugged, my cameras index change.

CAMA //GONE
CAMB = 0
CAMC = 1

So is there some way to remember which camera is which (other than displaying each camera to the user every single time...)? Perhaps logging some unique ID for the camera that can be then read in on restart?

In the device manager, I see under the properties of the USB device - Device Class guid which seems to be a somewhat persistent value. Is there a way to correlate this ID to the cam index?

I have searched here and tried the code here. I imagine stereovision users commonly run into this problem, so how have people managed this?

1 Answer
1

What I've done for production applications is to do the video handling completely outside of OpenCV and then convert the frames to OpenCV images and do further processing.

On Windows you could use DirectShow, and I've used camera-specific APIs as well. Not in any way portable or convenient, but it has the benefit of working. On the plus side, you usually get access to the full set of camera settings and features, rather than just the few properties OpenCV defines.