-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpicam.cpp
More file actions
75 lines (53 loc) · 1.48 KB
/
Copy pathpicam.cpp
File metadata and controls
75 lines (53 loc) · 1.48 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <raspicam/raspicam_cv.h>
#include <omp.h>
using namespace std;
using namespace cv;
int main ( int argc,char **argv ) {
raspicam::RaspiCam_Cv camera;
camera.set( CV_CAP_PROP_FORMAT, CV_8UC4 );
camera.set( CV_CAP_PROP_MODE, 2);
bool capture = false;
cv::VideoWriter writer;
if ( !camera.open()) {
cerr<<"Error opening camera"<<endl;
return -1;
}
Size sz = Size((int) camera.get(CV_CAP_PROP_FRAME_WIDTH), (int) camera.get(CV_CAP_PROP_FRAME_HEIGHT));
if (argc > 1 && atoi(argv[1]) == 1)
{
printf("capture true \n");
capture = true;
writer.open("output.avi", CV_FOURCC('M','P','4','2'), 10, sz, true);
if (!writer.isOpened())
printf("Error opening writer\n");
}
camera.grab();
Mat frame;
Mat frame_out;
camera.retrieve ( frame);
namedWindow("cam", CV_WINDOW_NORMAL);
cvSetWindowProperty("cam", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
bool terminate = false;
//#pragma omp parallel num_threads(1) shared(terminate, frame, frame_out) firstprivate(camera) default(none)
while(!terminate)
{
camera.grab();
camera.retrieve (frame);
imshow("cam", frame);
cvWaitKey(10);
if (waitKey(10) == 27 || terminate)
{
terminate = true;
}
if (capture)
writer.write(frame);
}
camera.release();
if (capture)
writer.release();
cout << "Returning cleanly" << endl;
return 0;
}