forked from wang-xinyu/tensorrtx
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusb_camera.cpp
More file actions
56 lines (45 loc) · 1.61 KB
/
usb_camera.cpp
File metadata and controls
56 lines (45 loc) · 1.61 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
//Open the default video camera
VideoCapture cap("/dev/video0");
// if not success, exit program
if (cap.isOpened() == false)
{
cout << "Cannot open the video camera" << endl;
cin.get(); //wait for any key press
return -1;
}
double dWidth = cap.get(CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Resolution of the video : " << dWidth << " x " << dHeight << endl;
string window_name = "My Camera Feed";
namedWindow(window_name); //create a window called "My Camera Feed"
while (true)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
//Breaking the while loop if the frames cannot be captured
if (bSuccess == false)
{
cout << "Video camera is disconnected" << endl;
cin.get(); //Wait for any key press
break;
}
//show the frame in the created window
imshow(window_name, frame);
//wait for for 10 ms until any key is pressed.
//If the 'Esc' key is pressed, break the while loop.
//If the any other key is pressed, continue the loop
//If any key is not pressed withing 10 ms, continue the loop
if (waitKey(10) == 27)
{
cout << "Esc key is pressed by user. Stoppig the video" << endl;
break;
}
}
return 0;
}