-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoProcess.h
More file actions
125 lines (95 loc) · 3.2 KB
/
VideoProcess.h
File metadata and controls
125 lines (95 loc) · 3.2 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// Created by Omri Carmi on 04/04/2018.
//
#ifndef VIDEOPROCESS_VIDEOPROCESS_H
#define VIDEOPROCESS_VIDEOPROCESS_H
#include <string>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
typedef struct VideoMeta_{
int currentFrameNumber;
double fps;
} VideoMeta;
class VideoProcess {
private:
string mVideoSrc;
VideoCapture mVideoCapture;
int x;
public:
VideoProcess(string videoSrc):mVideoSrc(videoSrc) {
//open the video file for reading
mVideoCapture.open(videoSrc);
// if not success, exit program
if (!mVideoCapture.isOpened())
{
throw "Cannot open the video file";
}
}
void play(){
// if not success, exit program
if (!mVideoCapture.isOpened())
{
throw "Cannot open the video file";
}
//Uncomment the following line if you want to start the video in the middle
//cap.set(CAP_PROP_POS_MSEC, 300);
//get the frames rate of the video
double fps = mVideoCapture.get(CAP_PROP_FPS);
cout << "Frames per seconds : " << fps << endl;
String window_name = "VideoWindow";
namedWindow(window_name, WINDOW_NORMAL); //create a window
while (true)
{
Mat frame;
bool bSuccess = mVideoCapture.read(frame); // read a new frame from video
//Breaking the while loop at the end of the video
if (bSuccess == false)
{
cout << "Found the end of the video" << endl;
break;
}
//show the frame in the created window
imshow(window_name, frame);
//wait for for 10 ms until any key is pressed.
//If the 'Esc' key is pressed, break the while loop.
//If the any other key is pressed, continue the loop
//If any key is not pressed withing 10 ms, continue the loop
if (waitKey(10) == 27)
{
cout << "Esc key is pressed by user. Stoppig the video" << endl;
break;
}
}
}
void process(void(*handler)(Mat frame,VideoMeta meta)){
// if not success, exit program
if (!mVideoCapture.isOpened())
{
throw "Cannot open the video file";
}
VideoMeta meta;
//Uncomment the following line if you want to start the video in the middle
//cap.set(CAP_PROP_POS_MSEC, 300);
//get the frames rate of the video
double fps = mVideoCapture.get(CAP_PROP_FPS);
cout << "Frames per seconds : " << fps << endl;
meta.fps = fps;
int currentFrameNumber = 0;
while (true)
{
Mat frame;
bool bSuccess = mVideoCapture.read(frame); // read a new frame from video
//Breaking the while loop at the end of the video
if (bSuccess == false)
{
cout << "Found the end of the video" << endl;
break;
}
meta.currentFrameNumber = (++currentFrameNumber);
//call the handler process function
handler(frame,meta);
}
}
};
#endif //VIDEOPROCESS_VIDEOPROCESS_H