How to count cameras in OpenCV 2.3?

后端 未结 6 1209
难免孤独
难免孤独 2020-12-01 14:36

I want to get the number of available cameras.

I tried to count cameras like this:

for(int device = 0; device<10; device++) 
{
    VideoCapture ca         


        
6条回答
  •  不知归路
    2020-12-01 14:52

    Even if it's an old post here a solution for OpenCV 2/C++

    /**
     * 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

    With 0 to 3 Usb Cameras

提交回复
热议问题