forked from wzpan/QtEVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoProcessor.h
280 lines (217 loc) · 7.49 KB
/
VideoProcessor.h
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// Yet anther C++ implementation of EVM, based on OpenCV and Qt.
// Copyright (C) 2014 Joseph Pan <[email protected]>
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA
//
#ifndef VIDEOPROCESSOR_H
#define VIDEOPROCESSOR_H
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <QObject>
#include <QDateTime>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include "SpatialFilter.h"
enum spatialFilterType {LAPLACIAN, GAUSSIAN};
enum temporalFilterType {IIR, IDEAL};
class VideoProcessor : public QObject {
Q_OBJECT
friend class MagnifyDialog;
public:
explicit VideoProcessor(QObject *parent = 0);
// Is the player playing?
bool isStop();
// Is the video modified?
bool isModified();
// Is the player opened?
bool isOpened();
// set a delay between each frame
// 0 means wait at each frame
// negative means no delay
void setDelay(int d);
// a count is kept of the processed frames
long getNumberOfProcessedFrames();
// get the current playing progress
long getNumberOfPlayedFrames();
// get the video capture
cv::VideoCapture getCapture();
// return the size of the video frame
cv::Size getFrameSize();
// return the frame number of the next frame
long getFrameNumber();
// return the position in milliseconds
double getPositionMS();
// return the frame rate
double getFrameRate();
// return the number of frames in video
long getLength();
// return the video length in milliseconds
double getLengthMS();
// get the codec of input video
int getCodec(char codec[4]);
// get temp file lists
void getTempFile(std::string &);
// get current temp file
void getCurTempFile(std::string &);
// go to this position expressed in fraction of total film length
bool setRelativePosition(double pos);
// set the name of the video file
bool setInput(const std::string &fileName);
// set the output video file
// by default the same parameters than input video will be used
bool setOutput(const std::string &filename, int codec=0, double framerate=0.0, bool isColor=true);
// set the output as a series of image files
// extension must be ".jpg", ".bmp" ...
bool setOutput(const std::string &filename, // filename prefix
const std::string &ext, // image file extension
int numberOfDigits=3, // number of digits
int startIndex=0); // start index
// set spatial filter
void setSpatialFilter(spatialFilterType type);
// set temporal filter
void setTemporalFilter(temporalFilterType type);
// play the frames of the sequence
void playIt();
// pause the frames of the sequence
void pauseIt();
// Stop playing
void stopIt();
// display the prev frame of the sequence
void prevFrame();
// display the next frame of the sequence
void nextFrame();
// Jump to a position
bool jumpTo(long index);
// Jump to a position in milliseconds
bool jumpToMS(double pos);
// close the video
void close();
// motion magnification
void motionMagnify();
// color magnification
void colorMagnify();
// write the processed result
void writeOutput();
private slots:
void revertVideo();
signals:
void showFrame(cv::Mat frame);
void revert();
void sleep(int msecs);
void updateBtn();
void updateProgressBar();
void reload(const std::string &);
void updateProcessProgress(const std::string &message, int percent);
void closeProgressDialog();
private:
// the OpenCV video capture object
cv::VideoCapture capture;
// delay between each frame processing
int delay;
// video frame rate
double rate;
// number of processed frames
long fnumber;
// total number of frames
long length;
// to stop the player
bool stop;
// is the video modified
bool modify;
// the current playing pos
long curPos;
// current index for output images
int curIndex;
// current level of pyramid
int curLevel;
// number of digits in output image filename
int digits;
// extension of output images
std::string extension;
// spatial filter type
spatialFilterType spatialType;
// temporal filter type
temporalFilterType temporalType;
// level numbers of image pyramid
int levels;
// amplification factor
float alpha;
// cut-off wave length
float lambda_c;
// low cut-off
float fl;
// high cut-off
float fh;
// chromAttenuation
double chromAttenuation;
// delta
float delta;
// extraggon factor
float exaggeration_factor;
// lambda
float lambda;
// the OpenCV video writer object
cv::VideoWriter writer;
cv::VideoWriter tempWriter;
// output filename
std::string outputFile;
// temp filename
std::string tempFile;
// all temp files queue
std::vector<std::string> tempFileList;
// low pass filters for IIR
std::vector<cv::gpu::GpuMat> lowpass1;
std::vector<cv::gpu::GpuMat> lowpass2;
// recalculate the number of frames in video
// normally doesn't need it unless getLength()
// can't return a valid value
void calculateLength();
// get the next frame if any
bool getNextFrame(cv::Mat& frame);
// to write the output frame
void writeNextFrame(cv::Mat& frame);
// set the temp video file
// by default the same parameters to the input video
bool createTemp(double framerate=0.0, bool isColor=true);
// spatial filtering
bool spatialFilter(const cv::gpu::GpuMat &src, std::vector<cv::gpu::GpuMat> &pyramid);
// temporal filtering
void temporalFilter(const cv::gpu::GpuMat &src,
cv::gpu::GpuMat &dst);
// temporal IIR filtering
void temporalIIRFilter(const cv::gpu::GpuMat &src,
cv::gpu::GpuMat &dst);
// temporal ideal bandpass filtering
void temporalIdealFilter(const cv::gpu::GpuMat &src,
cv::gpu::GpuMat &dst);
// amplify motion
void amplify(const cv::gpu::GpuMat &src, cv::gpu::GpuMat &dst);
// attenuate I, Q channels
void attenuate(cv::gpu::GpuMat &src, cv::gpu::GpuMat &dst);
// concat images into a large Mat
void concat(const std::vector<cv::gpu::GpuMat> &frames, cv::gpu::GpuMat &dst);
// de-concat the concatnate image into frames
void deConcat(const cv::gpu::GpuMat &src, const cv::Size &frameSize, std::vector<cv::gpu::GpuMat> &frames);
// create an ideal bandpass processor
void createIdealBandpassFilter(cv::Mat &filter, double fl, double fh, double rate);
};
#endif // VIDEOPROCESSOR_H