Capture picture with camera

Capture data with camera

Press $Space$ to capture
Press $ESC$ to exit

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
/*************************************************************************
> File Name: SplitVideo.cpp
> Author: zyy
> Mail: zyy34472@gmail.com
************************************************************************/


#include <iostream>
#include <string>
#include <ctime>
#include <sys/stat.h>
#include <sys/types.h>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

string getCurrentTime()
{

time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y-%m-%d-%X",localtime(&t) );
mkdir(tmp, S_IRWXU);
return string(tmp);
}

int main ()
{

Mat frame;
VideoCapture vc(0);
int i, fps, mykey;
string now = getCurrentTime();
for (i = 0, fps = 30; mykey = waitKey(1000/fps); i++) {
vc >> frame;
imshow("test", frame);
if (mykey == 32)
imwrite("./" + now + "/" + to_string(i) + ".jpg", frame);
else if (mykey == 27)
break;
}
return 0;
}

Contents
  1. 1. Capture data with camera