VidMag
Eulerian Video Magnification
VideoManager.hpp
Go to the documentation of this file.
1 /*
2 *
3 * VU Visualization 2
4 *
5 * Author: Dominik Bauer, Pascal Plank
6 * SS 2016
7 * All rights reserved.
8 *
9 */
10 
15 #ifndef VIDEOMANAGER
16 #define VIDEOMANAGER
17 
18 #include <iostream>
19 #include <iomanip>
20 #include <sstream>
21 #include <string>
22 #include <vector>
23 #include <vector>
24 #include <opencv2/core/core.hpp>
25 #include <opencv2/imgproc/imgproc.hpp>
26 #include <opencv2/highgui/highgui.hpp>
27 
28 // Enums for filtertypes
32 };
33 
35  IIR,
37 };
38 
39 
40 
41 class VideoManager {
42 
43 public:
44  explicit VideoManager();
45 
46  bool setInput(const std::string &fileName);
47 
48  // For saving the video to a special location
49  bool setOutput(const std::string &filename, int codec = 0, double framerate = 0.0, bool isColor = true);
50  void writeOutput();
51 
52  bool isOpened();
53  bool isStopped();
54  int getCodec(char codec[4]);
55  cv::Size getFrameSize();
56  double getFrameRate();
57  bool getNextFrame(cv::Mat& frame);
58  bool jumpTo(long index);
59  double getCurrentFrame();
60  double getNumberOfFrames();
61 
62  // Magnification functions
63  void motionMagnification();
64  void colorMagnification();
67  void setLevels(int lvls);
68 
69  // Magnification setter: Color and Motion
70  void setAlpha(float amplification);
71  void setLowCutoff(float low);
72  void setHighCutoff(float high);
73  void setFrequencyCutoffs(float low, float high);
74 
75  // Magnification setter: motion
76  void setMotionCutOffWavelength(float lambda);
77  void setExaggerationFactor(float factor);
78  void setChromAttenuation(float attenuation);
79 
80  void setMask(float x1, float y1, float x2, float y2, bool masked);
81 private:
82  //std::vector<cv::Mat> dispFrames;
83  //std::vector<cv::Mat> frames;
84 
85  //cv::VideoCapture capture;
86  cv::VideoWriter writer;
87  cv::VideoWriter tempWriter;
88 
89  double rate;
90  long fnumber; // number of processed frames
91  long length; // total number of frames
92  long curPos; // current playing position
93 
94  // Flags
95  bool modify; // indicates a modification of the current video
96  bool stopped; // true if playing video has been stopped
97 
98  // frame control
99 
100 
101 
102  void writeNextFrame(cv::Mat& frame);
103  int curIndex; // current index for the output images
104 
105  // set the temp video file which will be modified (default: same parameters as input)
106  bool createTemp(double framerate = 0.0, bool isColor = true);
107 
108  std::string tempFile;
109  std::vector<std::string> tempFileList; // list of all created temp-files
110  std::string outputFile;
111  std::string extension;
112  int digits; // number of digits in the output image filename
113 
114  // Pyramids and filtering
115  bool buildGaussianPyramid(const cv::Mat &img, const int levels, std::vector<cv::Mat> &pyramid);
116  bool buildLaplacianPyramid(const cv::Mat &img, const int levels, std::vector<cv::Mat> &pyramid);
117  void reconImgFromLaplacianPyramid(const std::vector<cv::Mat> &pyramid, const int levels, cv::Mat &dst);
118  void VideoManager::attenuate(cv::Mat &src, cv::Mat &dst);
119  void upsamplingFromGaussianPyramid(const cv::Mat &src, const int levels, cv::Mat &dst);
120  bool spatialFilter(const cv::Mat &src, std::vector<cv::Mat> &pyramid);
121  void temporalFilter(const cv::Mat &src, cv::Mat &dst);
122  int levels; // numbers of image pyramid levels
123  int curLevel;
124  spatialFilterType spatialType;
125  temporalFilterType temporalType;
126  void temporalIIRFilter(const cv::Mat &src, cv::Mat &dst);
127  void temporalIdealFilter(const cv::Mat &src, cv::Mat &dst);
128  void createIdealBandpassFilter(cv::Mat &filter, double fl, double fh, double rate);
129  // low pass filters for IIR
130  std::vector<cv::Mat> lowpass1;
131  std::vector<cv::Mat> lowpass2;
132  float delta;
133  void amplify(const cv::Mat &src, cv::Mat &dst);
134 
135  // Variables for color and motion magnification
136  float fl; // low cut-off
137  float fh; // high cut-off
138  float lambda; // representative wavelength lambda
139  float alpha; // amplification factor
140 
141  // Variables for motion magnifications
142  float lambda_c; // cut-off wavelength
143  float exaggeration_factor;
144  float chromAttenuation;
145 
146  void concat(const std::vector<cv::Mat> &frames, cv::Mat &dst);
147  void deConcat(const cv::Mat &src, const cv::Size &frameSize, std::vector<cv::Mat> &frames);
148 
149  bool useMask;
150  cv::Mat mask;
151 };
152 
153 #endif
void setLowCutoff(float low)
Definition: VideoManager.cpp:882
void motionMagnification()
Definition: VideoManager.cpp:211
double getNumberOfFrames()
Definition: VideoManager.cpp:49
void setTemporalFilter(temporalFilterType type)
Definition: VideoManager.cpp:506
void setMask(float x1, float y1, float x2, float y2, bool masked)
Definition: VideoManager.cpp:54
bool setOutput(const std::string &filename, int codec=0, double framerate=0.0, bool isColor=true)
Definition: VideoManager.cpp:114
Definition: VideoManager.hpp:36
Definition: VideoManager.hpp:30
void setFrequencyCutoffs(float low, float high)
Definition: VideoManager.cpp:901
double getFrameRate()
Definition: VideoManager.cpp:787
bool isStopped()
Definition: VideoManager.cpp:758
temporalFilterType
Definition: VideoManager.hpp:34
void setLevels(int lvls)
Definition: VideoManager.cpp:860
void setAlpha(float amplification)
Definition: VideoManager.cpp:873
bool setInput(const std::string &fileName)
Definition: VideoManager.cpp:82
bool isOpened()
Definition: VideoManager.cpp:749
double getCurrentFrame()
Definition: VideoManager.cpp:44
VideoManager()
Definition: VideoManager.cpp:19
void setChromAttenuation(float attenuation)
Definition: VideoManager.cpp:940
Definition: VideoManager.hpp:31
void setHighCutoff(float high)
Definition: VideoManager.cpp:891
cv::Size getFrameSize()
Definition: VideoManager.cpp:814
Definition: VideoManager.hpp:41
void setSpatialFilter(spatialFilterType type)
Definition: VideoManager.cpp:497
void setExaggerationFactor(float factor)
Definition: VideoManager.cpp:931
void setMotionCutOffWavelength(float lambda)
Definition: VideoManager.cpp:921
Definition: VideoManager.hpp:35
void colorMagnification()
Definition: VideoManager.cpp:334
bool getNextFrame(cv::Mat &frame)
Definition: VideoManager.cpp:797
int getCodec(char codec[4])
Definition: VideoManager.cpp:769
spatialFilterType
Definition: VideoManager.hpp:29
void writeOutput()
Definition: VideoManager.cpp:133
bool jumpTo(long index)
Definition: VideoManager.cpp:835