Visual Servoing Platform version 3.5.0
vpVideoReader.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See http://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Read videos and sequences of images .
33 *
34 * Authors:
35 * Nicolas Melchior
36 * Fabien Spindler
37 *
38 *****************************************************************************/
39
45#ifndef vpVideoReader_H
46#define vpVideoReader_H
47
48#include <string>
49
50#include <visp3/io/vpDiskGrabber.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
171class VISP_EXPORT vpVideoReader : public vpFrameGrabber
172{
173private:
175 vpDiskGrabber *m_imSequence;
176#if VISP_HAVE_OPENCV_VERSION >= 0x020100
178 cv::VideoCapture m_capture;
179 cv::Mat m_frame;
180 bool m_lastframe_unknown;
181#endif
183 typedef enum {
184 FORMAT_PGM,
185 FORMAT_PPM,
186 FORMAT_JPEG,
187 FORMAT_PNG,
188 // Formats supported by opencv
189 FORMAT_TIFF,
190 FORMAT_BMP,
191 FORMAT_DIB,
192 FORMAT_PBM,
193 FORMAT_RASTER,
194 FORMAT_JPEG2000,
195 // Video format
196 FORMAT_AVI,
197 FORMAT_MPEG,
198 FORMAT_MPEG4,
199 FORMAT_MTS,
200 FORMAT_MOV,
201 FORMAT_OGV,
202 FORMAT_WMV,
203 FORMAT_FLV,
204 FORMAT_MKV,
205 FORMAT_UNKNOWN
206 } vpVideoFormatType;
207
209 vpVideoFormatType m_formatType;
210
212 std::string m_videoName;
213 std::string m_frameName;
215 bool m_initFileName;
217 bool m_isOpen;
219 long m_frameCount; // Index of the next image
221 long m_firstFrame;
223 long m_lastFrame;
224 bool m_firstFrameIndexIsSet;
225 bool m_lastFrameIndexIsSet;
227 long m_frameStep;
228 double m_frameRate;
229
230 // private:
231 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
232 // vpVideoReader(const vpVideoReader &)
233 // : vpFrameGrabber(), m_imSequence(NULL),
234 // #if VISP_HAVE_OPENCV_VERSION >= 0x020100
235 // m_capture(), m_frame(),
236 // #endif
237 // m_formatType(FORMAT_UNKNOWN), m_initFileName(false), m_isOpen(false),
238 // m_frameCount(0), m_firstFrame(0), m_lastFrame(0),
239 // m_firstFrameIndexIsSet(false), m_lastFrameIndexIsSet(false)
240 // {
241 // throw vpException(vpException::functionNotImplementedError, "Not
242 // implemented!");
243 // }
244 // vpVideoReader &operator=(const vpVideoReader &){
245 // throw vpException(vpException::functionNotImplementedError, "Not
246 // implemented!"); return *this;
247 // }
248 //#endif
249
250public:
252 virtual ~vpVideoReader();
253
254 void acquire(vpImage<vpRGBa> &I);
256 void close() { ; }
257
261 inline bool end()
262 {
263 if (m_frameStep > 0) {
264 if (m_frameCount + m_frameStep > m_lastFrame)
265 return true;
266 } else if (m_frameStep < 0) {
267 if (m_frameCount + m_frameStep < m_firstFrame)
268 return true;
269 }
270 return false;
271 }
272 bool getFrame(vpImage<vpRGBa> &I, long frame);
273 bool getFrame(vpImage<unsigned char> &I, long frame);
280 {
281 if (!m_isOpen) {
282 getProperties();
283 }
284 return m_frameRate;
285 }
286
296 inline long getFrameIndex() const { return m_frameCount; }
297
301 inline std::string getFrameName() const { return m_frameName; }
302
308 inline long getFirstFrameIndex()
309 {
310 if (!m_isOpen) {
311 getProperties();
312 }
313 return m_firstFrame;
314 }
320 inline long getLastFrameIndex()
321 {
322 if (!m_isOpen) {
323 getProperties();
324 }
325 return m_lastFrame;
326 }
332 inline long getFrameStep() const { return m_frameStep; }
333
334 bool isVideoFormat() const;
335 void open(vpImage<vpRGBa> &I);
337
339 vpVideoReader &operator>>(vpImage<vpRGBa> &I);
340
349 inline void resetFrameCounter() { m_frameCount = m_firstFrame; }
350 void setFileName(const std::string &filename);
359 inline void setFirstFrameIndex(const long first_frame)
360 {
361 m_firstFrameIndexIsSet = true;
362 m_firstFrame = first_frame;
363 }
371 inline void setLastFrameIndex(const long last_frame)
372 {
373 this->m_lastFrameIndexIsSet = true;
374 m_lastFrame = last_frame;
375 }
376
385 inline void setFrameStep(const long frame_step) { m_frameStep = frame_step; }
386
387private:
388 vpVideoFormatType getFormat(const std::string &filename) const;
389 static std::string getExtension(const std::string &filename);
390 void findFirstFrameIndex();
391 void findLastFrameIndex();
392 bool isImageExtensionSupported() const;
393 bool isVideoExtensionSupported() const;
394 bool checkImageNameFormat(const std::string &format) const;
395 void getProperties();
396};
397
398#endif
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.
virtual void open(vpImage< unsigned char > &I)=0
virtual void acquire(vpImage< unsigned char > &I)=0
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void setLastFrameIndex(const long last_frame)
long getLastFrameIndex()
void resetFrameCounter()
void setFirstFrameIndex(const long first_frame)
long getFirstFrameIndex()
void setFrameStep(const long frame_step)
long getFrameStep() const
std::string getFrameName() const
double getFramerate()
long getFrameIndex() const