-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
45 lines (37 loc) · 994 Bytes
/
test.cpp
File metadata and controls
45 lines (37 loc) · 994 Bytes
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
#include <opencv2/opencv.hpp>
#include <iostream>
#include <thread>
#include <chrono>
using namespace cv;
int main()
{
Mat frame;
VideoCapture cap;
int deviceID = 2; // Select the ID of the USB camera we want - 0 = default
int apiID = CAP_V4L2; // ??
cap.open(deviceID, apiID); // Opens selected cam using selected API
// Error if fail to open cam
if (!cap.isOpened()) {
std::cerr << "ERROR! Unable to open camera\n";
return -1;
}
std::cout << "Sleep" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Starting to grab (??)" << std::endl;
while (true)
{
cap.read(frame); // I think this reads *into* the frame?
// Break on err
if (frame.empty())
{
std::cerr << "ERROR! Blank frame grabbed\n";
break;
}
// Show image
imshow("Live", frame);
// Break if key pressed (??)
if (waitKey(5) >= 0)
break;
}
return 0;
}