ViSP  2.10.0
vpVideoReader.h
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.h 2359 2009-11-24 15:09:25Z nmelchio $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Read videos and sequences of images .
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
48 #ifndef vpVideoReader_H
49 #define vpVideoReader_H
50 
51 #include <string>
52 
53 #include <visp/vpDiskGrabber.h>
54 #include <visp/vpFFMPEG.h>
55 
56 #if VISP_HAVE_OPENCV_VERSION >= 0x020200
57 #include "opencv2/highgui/highgui.hpp"
58 #elif VISP_HAVE_OPENCV_VERSION >= 0x020000
59 #include "opencv/highgui.h"
60 #endif
61 
163 class VISP_EXPORT vpVideoReader : public vpFrameGrabber
164 {
165  private:
167  vpDiskGrabber *imSequence;
168 #ifdef VISP_HAVE_FFMPEG
169  vpFFMPEG *ffmpeg;
171 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
172  cv::VideoCapture capture;
174  cv::Mat frame;
175 #endif
176  typedef enum
178  {
179  FORMAT_PGM,
180  FORMAT_PPM,
181  FORMAT_JPEG,
182  FORMAT_PNG,
183  // Formats supported by opencv
184  FORMAT_TIFF,
185  FORMAT_BMP,
186  FORMAT_DIB,
187  FORMAT_PBM,
188  FORMAT_RASTER,
189  FORMAT_JPEG2000,
190  // Video format
191  FORMAT_AVI,
192  FORMAT_MPEG,
193  FORMAT_MPEG4,
194  FORMAT_MOV,
195  FORMAT_OGV,
196  FORMAT_WMV,
197  FORMAT_FLV,
198  FORMAT_MKV,
199  FORMAT_UNKNOWN
200  } vpVideoFormatType;
201 
203  vpVideoFormatType formatType;
204 
206  char fileName[FILENAME_MAX];
208  bool initFileName;
210  bool isOpen;
212  long frameCount; // Index of the next image
214  long firstFrame;
216  long lastFrame;
217  bool firstFrameIndexIsSet;
218  bool lastFrameIndexIsSet;
219 
220  public:
221  vpVideoReader();
222  ~vpVideoReader();
223 
224  void acquire(vpImage< vpRGBa > &I);
226  void close(){;}
227 
231  inline bool end() {
232  if (frameCount > lastFrame )
233  return true;
234  return false;
235  }
236  bool getFrame(vpImage<vpRGBa> &I, long frame);
237  bool getFrame(vpImage<unsigned char> &I, long frame);
238  double getFramerate();
239 
247  inline long getFrameIndex() const { return frameCount;}
248 
254  inline long getFirstFrameIndex() const {return firstFrame;}
260  inline long getLastFrameIndex() const {return lastFrame;}
261  void open (vpImage< vpRGBa > &I);
262  void open (vpImage< unsigned char > &I);
263 
271  inline void resetFrameCounter() {frameCount = firstFrame;}
272  void setFileName(const char *filename);
273  void setFileName(const std::string &filename);
282  inline void setFirstFrameIndex(const long first_frame) {
283  this->firstFrameIndexIsSet = true;
284  this->firstFrame = first_frame;
285  }
293  inline void setLastFrameIndex(const long last_frame) {
294  this->lastFrameIndexIsSet = true;
295  this->lastFrame = last_frame;
296  }
297 
298  private:
299  vpVideoFormatType getFormat(const char *filename);
300  static std::string getExtension(const std::string &filename);
301  void findFirstFrameIndex();
302  void findLastFrameIndex();
303  bool isImageExtensionSupported();
304  bool isVideoExtensionSupported();
305 };
306 
307 #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:149
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