Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpVideoReader.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
170 class VISP_EXPORT vpVideoReader : public vpFrameGrabber
171 {
172  private:
174  vpDiskGrabber *imSequence;
175 #ifdef VISP_HAVE_FFMPEG
176  vpFFMPEG *ffmpeg;
178 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
179  cv::VideoCapture capture;
181  cv::Mat frame;
182 #endif
183  typedef enum
185  {
186  FORMAT_PGM,
187  FORMAT_PPM,
188  FORMAT_JPEG,
189  FORMAT_PNG,
190  // Formats supported by opencv
191  FORMAT_TIFF,
192  FORMAT_BMP,
193  FORMAT_DIB,
194  FORMAT_PBM,
195  FORMAT_RASTER,
196  FORMAT_JPEG2000,
197  // Video format
198  FORMAT_AVI,
199  FORMAT_MPEG,
200  FORMAT_MPEG4,
201  FORMAT_MOV,
202  FORMAT_OGV,
203  FORMAT_WMV,
204  FORMAT_FLV,
205  FORMAT_MKV,
206  FORMAT_UNKNOWN
207  } vpVideoFormatType;
208 
210  vpVideoFormatType formatType;
211 
213  char fileName[FILENAME_MAX];
215  bool initFileName;
217  bool isOpen;
219  long frameCount; // Index of the next image
221  long firstFrame;
223  long lastFrame;
224  bool firstFrameIndexIsSet;
225  bool lastFrameIndexIsSet;
226 
227 //private:
228 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
229 // vpVideoReader(const vpVideoReader &)
230 // : vpFrameGrabber(), imSequence(NULL),
231 // #ifdef VISP_HAVE_FFMPEG
232 // ffmpeg(NULL),
233 // #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
234 // capture(), frame(),
235 // #endif
236 // formatType(FORMAT_UNKNOWN), initFileName(false), isOpen(false), frameCount(0),
237 // firstFrame(0), lastFrame(0), firstFrameIndexIsSet(false), lastFrameIndexIsSet(false)
238 // {
239 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
240 // }
241 // vpVideoReader &operator=(const vpVideoReader &){
242 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
243 // return *this;
244 // }
245 //#endif
246 
247  public:
248  vpVideoReader();
249  ~vpVideoReader();
250 
251  void acquire(vpImage< vpRGBa > &I);
253  void close(){;}
254 
258  inline bool end() {
259  if (frameCount > lastFrame )
260  return true;
261  return false;
262  }
263  bool getFrame(vpImage<vpRGBa> &I, long frame);
264  bool getFrame(vpImage<unsigned char> &I, long frame);
265  double getFramerate();
266 
274  inline long getFrameIndex() const { return frameCount;}
275 
281  inline long getFirstFrameIndex() const {return firstFrame;}
287  inline long getLastFrameIndex() const {return lastFrame;}
288  void open (vpImage< vpRGBa > &I);
289  void open (vpImage< unsigned char > &I);
290 
291  vpVideoReader & operator>>(vpImage<unsigned char> &I);
292  vpVideoReader & operator>>(vpImage<vpRGBa> &I);
293 
301  inline void resetFrameCounter() {frameCount = firstFrame;}
302  void setFileName(const char *filename);
303  void setFileName(const std::string &filename);
312  inline void setFirstFrameIndex(const long first_frame) {
313  this->firstFrameIndexIsSet = true;
314  this->firstFrame = first_frame;
315  }
323  inline void setLastFrameIndex(const long last_frame) {
324  this->lastFrameIndexIsSet = true;
325  this->lastFrame = last_frame;
326  }
327 
328  private:
329  vpVideoFormatType getFormat(const char *filename);
330  static std::string getExtension(const std::string &filename);
331  void findFirstFrameIndex();
332  void findLastFrameIndex();
333  bool isImageExtensionSupported();
334  bool isVideoExtensionSupported();
335 };
336 
337 #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