-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencv-grab.cpp
More file actions
53 lines (41 loc) · 1.31 KB
/
opencv-grab.cpp
File metadata and controls
53 lines (41 loc) · 1.31 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
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int, char**)
{
Mat frame;
VideoCapture cap;
cap.open(0, cv::CAP_V4L2);
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
cout << "Set PROP_FOURCC" << endl;
bool r = cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y','U','Y','V'));
if (!r) {
std::cout << "error cap.set()" << std::endl;
return -1;
}
cap.set(CAP_PROP_FRAME_WIDTH,320);
cap.set(CAP_PROP_FRAME_HEIGHT,240);
cout << "Camera frame W " << dec << cap.get(CAP_PROP_FRAME_WIDTH);
cout << "; Camera frame H " << dec << cap.get(CAP_PROP_FRAME_HEIGHT);
cout << "; Format " << dec << cap.get(CAP_PROP_FORMAT) << endl;
cout << "Start grabbing" << endl;
cap.read(frame);
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed" << endl;
return -1;
} else {
cout << "I Have a frame!\n";
}
cout << "Frame size: W " << frame.cols << ", H " << frame.rows << endl;
cout << "Frame channels:" << frame.channels() << endl;
if (imwrite("frame.jpg", frame)) {
cout << "Frame written to file" << endl;
} else {
cerr << "ERROR! write to file failed" << endl;
}
return 0;
}