How to get camera id for VideoCapture?
From the specification page of "VideoCapture" , we know there is one constuctor "VideoCapture (int index);", and "index" here is the camera id which is provided by operating systems. In my computer, there are several cameros, so, how to get their id-s for feeding VideoCapture?
B.T.W, My Operating System is Windows.
EnumerateCameras
function in my answer should helpThanks for your code. It seems a traversing way. It is good! I want to know if there is some other way, e.g. utilize Windows SDK (e.g. DirectShow API or MS Media Foundation API) to get the camera id-s in integer type? (As far as I know, it seems DirectShow API or MF API cannot do this. I'm new to OpenCV or video processing. I may be wrong.) Anyway, you can paste the above code here as an answer if you want.
Yes I used brute force to enumerate all working ID in OpenCV. I can't find any other way to get camera ID for VideoCapture. The function returns a vector of all available ID, you can easily get all IDs as int. Out of OpenCV should be some solution but OpenCV uses
CV_CAP_driver
as base for cam ID that is specific.