VisualizeVideo
 All Classes Functions Pages
VideoManager.h
1 #pragma once
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <sstream>
6 #include <string>
7 #include <vector>
8 #include <opencv\cv.h>
9 #include <opencv2/core/core.hpp>
10 #include <opencv2/highgui/highgui.hpp>
11 #include <opencv2/imgproc/imgproc.hpp>
12 #include <opencv2/video/video.hpp>
13 #include <opencv2/video/background_segm.hpp>
14 #include "VolumeData.h"
15 #include "saliency.h"
16 
17 using namespace cv;
18 
19 
20 /*------------------------------------------------------------------------------------------*\
21  This file contains material supporting chapter 10 of the cookbook:
22  Computer Vision Programming using the OpenCV Library.
23  by Robert Laganiere, Packt Publishing, 2011.
24 
25  This program is free software; permission is hereby granted to use, copy, modify,
26  and distribute this source code, or portions thereof, for any purpose, without fee,
27  subject to the restriction that the copyright notice may not be removed
28  or altered from any source or altered source distribution.
29  The software is released on an as-is basis and without any warranties of any kind.
30  In particular, the software is not guaranteed to be fault-tolerant or free from failure.
31  The author disclaims all warranties with regard to this software, any use,
32  and any consequent failure, is purely the responsibility of the user.
33 
34  Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
35 \*------------------------------------------------------------------------------------------*/
36 
39 
40  public:
41  // processing method
42  virtual void process(cv:: Mat &input, cv:: Mat &output)= 0;
43 };
44 
46 
72 {
73 private:
74 
75  // the OpenCV video capture object
76  cv::VideoCapture capture;
77  bool toggleSaliencyDetect;
78  // the callback function to be called
79  // for the processing of each frame
80  void (*process)(cv::Mat&, cv::Mat&);
81  // the pointer to the class implementing
82  // the FrameProcessor interface
83  FrameProcessor *frameProcessor;
84  // a bool to determine if the
85  // process callback will be called
86  bool callIt;
87  // Input display window name
88  std::string windowNameInput;
89  // Output display window name
90  std::string windowNameOutput;
91  // delay between each frame processing
92  int delay;
93  // number of processed frames
94  long fnumber;
95  // stop at this frame number
96  long frameToStop;
97  // to stop the processing
98  bool stop;
99 
100  // vector of image filename to be used as input
101  std::vector<std::string> images;
102  // image vector iterator
103  std::vector<std::string>::const_iterator itImg;
104 
105  // the OpenCV video writer object
106  cv::VideoWriter writer;
107  // output filename
108  std::string outputFile;
109 
110  // current index for output images
111  int currentIndex;
112  // number of digits in output image filename
113  int digits;
114  // extension of output images
115  std::string extension;
116 
117  bool readNextFrame(cv::Mat& frame);
118  void writeNextFrame(cv::Mat& frame);
119 
120  VolumeData volume;
121 
122  //static const int MAX_FRAMES = 100;
123  int maxFrames;
124  int startFrame;
125  int fps;
126 
127 public:
128 
132  VideoManager() : callIt(false), delay(-1),
133  fnumber(0), stop(false), digits(0), frameToStop(-1),
134  process(0), frameProcessor(0) {}
135  ~VideoManager(void);
136 
138 
146  bool setInput(std::string filename, bool performSaliencyDetect, int skippedFrames, int startFr, int maxFr);
147 
149 
157  bool setInput(int id, bool performSaliencyDetect, int skippedFrames, int startFr, int maxFr);
159 
167  bool setInput(const std::vector<std::string>& imgs, bool performSaliencyDetect, int skippedFrames, int startFr, int maxFr);
168  bool setOutput(const std::string &filename, int codec=0, double framerate=0.0, bool isColor=true);
169  bool setOutput(const std::string &filename, const std::string &ext, int numberOfDigits=3, int startIndex=0);
170  void setFrameProcessor(void (*frameProcessingCallback)(cv::Mat&, cv::Mat&));
171  void setFrameProcessor(FrameProcessor* frameProcessorPtr);
172  void stopAtFrameNo(long frame);
173  void callProcess();
174  void dontCallProcess();
175  void displayInput(std::string wn);
176  void displayOutput(std::string wn);
177  void dontDisplay();
178  void setDelay(int d);
179  long getNumberOfProcessedFrames();
180  cv::Size getFrameSize();
181  long getFrameNumber();
182  double getPositionMS();
183  double getFrameRate();
184  long getTotalFrameCount();
185  int getCodec(char codec[4]);
186  bool setFrameNumber(long pos);
187  bool setPositionMS(double pos);
188  bool setRelativePosition(double pos);
189  void stopIt();
190  bool isStopped();
191  bool isOpened();
193  void run(VolumeData& vol);
194 };
195