I do not think that OpenCV provides any function to determine how many cameras are detected. A simple and cross-platform way is to call VideoCapture::open()in a loop from 0 to 10, and in each iteration check if it returns VideoCapture::isOpened() true. Thus, you know the index of cameras and the number of them you have.
source
share