Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpVideoReader.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
39#ifndef _vpVideoReader_h_
40#define _vpVideoReader_h_
41
42#include <string>
43
44#include <visp3/io/vpDiskGrabber.h>
45
46#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI)
47#include <opencv2/videoio/videoio.hpp>
48#include <opencv2/highgui/highgui.hpp>
49#endif
50
164class VISP_EXPORT vpVideoReader : public vpFrameGrabber
165{
166private:
168 vpDiskGrabber *m_imSequence;
169#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
171 cv::VideoCapture m_capture;
172 cv::Mat m_frame;
173 bool m_lastframe_unknown;
174#endif
176 typedef enum {
177 FORMAT_PGM,
178 FORMAT_PPM,
179 FORMAT_JPEG,
180 FORMAT_PNG,
181 // Formats supported by opencv
182 FORMAT_TIFF,
183 FORMAT_BMP,
184 FORMAT_DIB,
185 FORMAT_PBM,
186 FORMAT_RASTER,
187 FORMAT_JPEG2000,
188 // Video format
189 FORMAT_AVI,
190 FORMAT_MPEG,
191 FORMAT_MPEG4,
192 FORMAT_MTS,
193 FORMAT_MOV,
194 FORMAT_OGV,
195 FORMAT_WMV,
196 FORMAT_FLV,
197 FORMAT_MKV,
198 FORMAT_UNKNOWN
199 } vpVideoFormatType;
200
202 vpVideoFormatType m_formatType;
203
205 std::string m_videoName;
206 std::string m_frameName;
208 bool m_initFileName;
210 bool m_isOpen;
212 long m_frameCount; // Index of the next image
214 long m_firstFrame;
216 long m_lastFrame;
217 bool m_firstFrameIndexIsSet;
218 bool m_lastFrameIndexIsSet;
220 long m_frameStep;
221 double m_frameRate;
222
223public:
225 virtual ~vpVideoReader();
226
227 void acquire(vpImage<vpRGBa> &I);
229 void close() { ; }
230
234 inline bool end()
235 {
236 if (m_frameStep > 0) {
237 if (m_frameCount + m_frameStep > m_lastFrame)
238 return true;
239 } else if (m_frameStep < 0) {
240 if (m_frameCount + m_frameStep < m_firstFrame)
241 return true;
242 }
243 return false;
244 }
245 bool getFrame(vpImage<vpRGBa> &I, long frame);
246 bool getFrame(vpImage<unsigned char> &I, long frame);
253 {
254 if (!m_isOpen) {
255 getProperties();
256 }
257 return m_frameRate;
258 }
259
269 inline long getFrameIndex() const { return m_frameCount; }
270
274 inline std::string getFrameName() const { return m_frameName; }
275
281 inline long getFirstFrameIndex()
282 {
283 if (!m_isOpen) {
284 getProperties();
285 }
286 return m_firstFrame;
287 }
293 inline long getLastFrameIndex()
294 {
295 if (!m_isOpen) {
296 getProperties();
297 }
298 return m_lastFrame;
299 }
305 inline long getFrameStep() const { return m_frameStep; }
306
307 bool isVideoFormat() const;
308 void open(vpImage<vpRGBa> &I);
310
312 vpVideoReader &operator>>(vpImage<vpRGBa> &I);
313
322 inline void resetFrameCounter() { m_frameCount = m_firstFrame; }
323 void setFileName(const std::string &filename);
332 inline void setFirstFrameIndex(const long first_frame)
333 {
334 m_firstFrameIndexIsSet = true;
335 m_firstFrame = first_frame;
336 }
344 inline void setLastFrameIndex(const long last_frame)
345 {
346 this->m_lastFrameIndexIsSet = true;
347 m_lastFrame = last_frame;
348 }
349
358 inline void setFrameStep(const long frame_step) { m_frameStep = frame_step; }
359
360private:
361 vpVideoFormatType getFormat(const std::string &filename) const;
362 static std::string getExtension(const std::string &filename);
363 void findFirstFrameIndex();
364 void findLastFrameIndex();
365 bool isImageExtensionSupported() const;
366 bool isVideoExtensionSupported() const;
367 bool checkImageNameFormat(const std::string &format) const;
368 void getProperties();
369};
370
371#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
Definition of the vpImage class member functions.
Definition vpImage.h:135
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