get the number of camera devices

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

get the number of camera devices

opencv-users mailing list
How to get number of connected camera devices names and ports in Opencv?

Is there any function available to the get the number of camera devices
connected with opencv?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: get the number of camera devices

opencv-users mailing list
without using system calls, you have to try to open devices yourself, and
checking whether the connection was opened or not.

Il giorno lun 6 apr 2015 alle ore 22:16 Alrabi opencv [hidden email]
[OpenCV] <[hidden email]> ha scritto:

>
>
> How to get number of connected camera devices names and ports in Opencv?
>
> Is there any function available to the get the number of camera devices
> connected with opencv?
>
> Thanks
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: get the number of camera devices

opencv-users mailing list
/*

g++ pro.cpp -o pro `pkg-config --cflags --libs opencv`

*/
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;



                       
int countCameras() {

      int maxTested = 10;
      int i,c;
      for (i = 0; i < maxTested; i++)
          {
            VideoCapture temp_camera(i);

            bool res = (!temp_camera.isOpened());

            temp_camera.release();


            if (res)
              {
                return i;
               }
           }
//   return maxTested;


}


int main()
{
int ii = countCameras();
    cout<< "Because we reached the end of the internal list,\n";
    cout<< "\n\n\n                        "<< ii <<"  cameras detected by opencv" << "\n\n\n\n";
return 0;
}