opencv中获取摄像头的个数:在国外网站上看到的
** * Get the number of camera available */ int countCameras() { cv::VideoCapture temp_camera; int maxTested = 10; for (int i = 0; i < maxTested; i++){ cv::VideoCapture temp_camera(i); bool res = (!temp_camera.isOpened()); temp_camera.release(); if (res) { return i; } } return maxTested; }
Tested under Windows 7 x64 with :
- OpenCV 3 [Custom Build]
- OpenCV 2.4.9
- OpenCV 2.4.8