Visual Servoing Platform  version 3.0.0
vpVideoReader.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Read videos and sequences of images .
32  *
33  * Authors:
34  * Nicolas Melchior
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
44 #ifndef vpVideoReader_H
45 #define vpVideoReader_H
46 
47 #include <string>
48 
49 #include <visp3/io/vpDiskGrabber.h>
50 #include <visp3/io/vpFFMPEG.h>
51 
52 #if VISP_HAVE_OPENCV_VERSION >= 0x020200
53 #include "opencv2/highgui/highgui.hpp"
54 #elif VISP_HAVE_OPENCV_VERSION >= 0x020000
55 #include "opencv/highgui.h"
56 #endif
57 
159 class VISP_EXPORT vpVideoReader : public vpFrameGrabber
160 {
161  private:
163  vpDiskGrabber *imSequence;
164 #ifdef VISP_HAVE_FFMPEG
165  vpFFMPEG *ffmpeg;
167 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
168  cv::VideoCapture capture;
170  cv::Mat frame;
171 #endif
172  typedef enum
174  {
175  FORMAT_PGM,
176  FORMAT_PPM,
177  FORMAT_JPEG,
178  FORMAT_PNG,
179  // Formats supported by opencv
180  FORMAT_TIFF,
181  FORMAT_BMP,
182  FORMAT_DIB,
183  FORMAT_PBM,
184  FORMAT_RASTER,
185  FORMAT_JPEG2000,
186  // Video format
187  FORMAT_AVI,
188  FORMAT_MPEG,
189  FORMAT_MPEG4,
190  FORMAT_MOV,
191  FORMAT_OGV,
192  FORMAT_WMV,
193  FORMAT_FLV,
194  FORMAT_MKV,
195  FORMAT_UNKNOWN
196  } vpVideoFormatType;
197 
199  vpVideoFormatType formatType;
200 
202  char fileName[FILENAME_MAX];
204  bool initFileName;
206  bool isOpen;
208  long frameCount; // Index of the next image
210  long firstFrame;
212  long lastFrame;
213  bool firstFrameIndexIsSet;
214  bool lastFrameIndexIsSet;
215 
216 //private:
217 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
218 // vpVideoReader(const vpVideoReader &)
219 // : vpFrameGrabber(), imSequence(NULL),
220 // #ifdef VISP_HAVE_FFMPEG
221 // ffmpeg(NULL),
222 // #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
223 // capture(), frame(),
224 // #endif
225 // formatType(FORMAT_UNKNOWN), initFileName(false), isOpen(false), frameCount(0),
226 // firstFrame(0), lastFrame(0), firstFrameIndexIsSet(false), lastFrameIndexIsSet(false)
227 // {
228 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
229 // }
230 // vpVideoReader &operator=(const vpVideoReader &){
231 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
232 // return *this;
233 // }
234 //#endif
235 
236  public:
237  vpVideoReader();
238  ~vpVideoReader();
239 
240  void acquire(vpImage< vpRGBa > &I);
242  void close(){;}
243 
247  inline bool end() {
248  if (frameCount > lastFrame )
249  return true;
250  return false;
251  }
252  bool getFrame(vpImage<vpRGBa> &I, long frame);
253  bool getFrame(vpImage<unsigned char> &I, long frame);
254  double getFramerate();
255 
263  inline long getFrameIndex() const { return frameCount;}
264 
270  inline long getFirstFrameIndex() const {return firstFrame;}
276  inline long getLastFrameIndex() const {return lastFrame;}
277  void open (vpImage< vpRGBa > &I);
278  void open (vpImage< unsigned char > &I);
279 
287  inline void resetFrameCounter() {frameCount = firstFrame;}
288  void setFileName(const char *filename);
289  void setFileName(const std::string &filename);
298  inline void setFirstFrameIndex(const long first_frame) {
299  this->firstFrameIndexIsSet = true;
300  this->firstFrame = first_frame;
301  }
309  inline void setLastFrameIndex(const long last_frame) {
310  this->lastFrameIndexIsSet = true;
311  this->lastFrame = last_frame;
312  }
313 
314  private:
315  vpVideoFormatType getFormat(const char *filename);
316  static std::string getExtension(const std::string &filename);
317  void findFirstFrameIndex();
318  void findLastFrameIndex();
319  bool isImageExtensionSupported();
320  bool isVideoExtensionSupported();
321 };
322 
323 #endif
long getFrameIndex() const
long getFirstFrameIndex() const
long getLastFrameIndex() const
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
virtual void open(vpImage< unsigned char > &I)=0
void resetFrameCounter()
This class interfaces the FFmpeg library to enable video stream reading or writing.
Definition: vpFFMPEG.h:145
Class to grab (ie. read) images from the disk.
Base class for all video devices. It is designed to provide a front end to video sources.
void setLastFrameIndex(const long last_frame)
void setFirstFrameIndex(const long first_frame)
virtual void acquire(vpImage< unsigned char > &I)=0