vivalib library
Concurrent C++11 OpenCV library for Computer Vision applications
input.h
1 /**************************************************************************************************
2  **************************************************************************************************
3 
4  BSD 3-Clause License (https://www.tldrlegal.com/l/bsd3)
5 
6  Copyright (c) 2015 Andrés Solís Montero <http://www.solism.ca>, All rights reserved.
7 
8 
9  Redistribution and use in source and binary forms, with or without modification,
10  are permitted provided that the following conditions are met:
11 
12  1. Redistributions of source code must retain the above copyright notice,
13  this list of conditions and the following disclaimer.
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17  3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30  OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32  **************************************************************************************************
33  **************************************************************************************************/
34 
35 #ifndef __viva__input__
36 #define __viva__input__
37 
38 #include "opencv2/opencv.hpp"
39 #include "utils.h"
40 #include <vector>
41 
42 using namespace cv;
43 using namespace std;
44 
45 namespace viva
46 {
47 
51  class Input
52  {
53  protected:
54  Size _size;
55  bool _convert;
56  int _conversionFlag;
57  Size _orgSize;
58 
59  public:
67  Input(const Size &size = Size(-1, -1),
68  int conversionFlag = -1):
69  _size(size), _convert(false),
70  _conversionFlag(conversionFlag)
71  {
72  if (_conversionFlag != -1)
73  _convert = true;
74  }
80  virtual bool getFrame(Mat &image) = 0;
81 
85  virtual ~Input(){}
86 
92  void setConversionType(int flag)
93  {
94  _conversionFlag = flag;
95  }
96 
100  size_t getWidth()
101  {
102  return _size.width;
103  }
107  size_t getHeight()
108  {
109  return _size.height;
110  }
116  Size getOrgSize()
117  {
118  return _orgSize;
119  }
120 
121  };
122 
123 
127  class VideoInput: public Input
128  {
129  protected:
130  VideoCapture _CameraInput;
131  bool _opened;
132  public:
143  VideoInput(const string &filename, const Size &size = Size(-1,-1), int colorFlag = -1);
144 
152  VideoInput(const int id, const Size &size = Size(-1, -1), int colorFlag = -1);
153 
157  VideoInput();
158 
162  ~VideoInput();
163 
169  bool getFrame(Mat &frame);
170  };
171 
175  typedef VideoInput CameraInput;
176 
180  typedef VideoInput WebStreamInput;
181 
185  typedef VideoInput SequenceInput;
186 
191  class ImageListInput: public Input
192  {
193  private:
194  vector<string> _filenames;
195  vector<string>::iterator _it;
196  int _loops;
197  bool _opened;
198 
199  void initialize();
200 
201  public:
205  ImageListInput(const string directory,
206  const Size &size = Size(-1,-1),
207  int colorFlag = -1,
208  int loops = 1);
213  ImageListInput(const vector<string> &files,
214  const Size &size = Size(-1,-1),
215  int colorFlag = -1,
216  int loops = 1);
217 
223  bool getFrame(Mat &frame);
224 
225 
226  };
227 }
228 
229 
230 
231 
232 
233 #endif /* defined(__viva__input__) */
size_t getHeight()
Definition: input.h:107
virtual ~Input()
Definition: input.h:85
Definition: input.h:51
Definition: input.h:191
Definition: channel.h:45
Size getOrgSize()
Definition: input.h:116
size_t getWidth()
Definition: input.h:100
Definition: input.h:127
Input(const Size &size=Size(-1,-1), int conversionFlag=-1)
Definition: input.h:67
void setConversionType(int flag)
Definition: input.h:92