-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.cpp
43 lines (37 loc) · 991 Bytes
/
camera.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
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)
{
std::cout<<"index of camera"<<i<<std::endl;
}
}
return maxTested;
}
int main(int, char**)
{
VideoCapture cap(1); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("frame",1);
std::cout<<"number of camera ="<<countCameras<<std::endl;
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
printf("size = %d %d \n",frame.cols,frame.rows);
imshow("frame", frame);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}