-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.cpp
67 lines (64 loc) · 2.08 KB
/
video.cpp
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
//
// Created by user on 2/25/17.
//
#include "video.h"
#include "globals.h"
void Video::openVideo(const String& videoName, Mat &frame) {
VideoCapture cap = VideoCapture(videoName, CAP_FFMPEG);
// check if we succeeded
if(!cap.isOpened()) {
cout << "Capture did not succeed to open " << videoName << std::endl;
return;
}
cap >> frame;
this->initCallback();
while(cap.isOpened()){
clock_t tStart = clock();
this->doThingsCallback();
this->drawCallback();
bool signalFromProg = this->stopAtFrame();
double timeTaken = (double)(clock() - tStart)/CLOCKS_PER_SEC;
printf("Time taken: %.2f ms\n", timeTaken*100.0);
cap >> frame;
char key = (char) waitKey(frameTime - (int)(timeTaken * 100.0 + 1));
if (signalFromProg || advanceOnlyOneFrame) {
key = 'p';
advanceOnlyOneFrame = false;
}
switch (key){
case 'p':
paused = true;
while(paused){
char k = (char) waitKey(frameTime);
if (k == 'p')
paused = false;
if (k == 'k') {
stopping = true;
paused = false;
}
if (k == 'n') {
paused = false;
advanceOnlyOneFrame = true;
}
if (k == 'z')
Globals::drawZones = !Globals::drawZones;
}
if (stopping)
return;
break;
case 'k':
return;
case 'z':
Globals::drawZones = !Globals::drawZones;
default:
break;
}
}
}
Video::Video(Callback initCallback, Callback doThingsCallback, Callback drawCallback, IsWaitingCallback stopAtFrame)
{
this->initCallback = initCallback;
this->doThingsCallback = doThingsCallback;
this->drawCallback = drawCallback;
this->stopAtFrame = stopAtFrame;
}