Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpVideoReader.h
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2025 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
38
39
#ifndef VP_VIDEO_READER_H
40
#define VP_VIDEO_READER_H
41
42
#include <string>
43
44
#include <visp3/core/vpConfig.h>
45
#include <visp3/io/vpDiskGrabber.h>
46
47
#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)
48
#include <opencv2/highgui/highgui.hpp>
49
#elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)
50
#include <opencv2/videoio/videoio.hpp>
51
#endif
52
53
BEGIN_VISP_NAMESPACE
54
179
180
class
VISP_EXPORT
vpVideoReader
:
public
vpFrameGrabber
181
{
182
private
:
184
vpDiskGrabber
*m_imSequence;
185
#if defined(VISP_HAVE_OPENCV) && \
186
(((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
187
((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
189
cv::VideoCapture m_capture;
190
cv::Mat m_frame;
191
bool
m_lastframe_unknown;
192
#endif
194
typedef
enum
195
{
196
FORMAT_PGM,
197
FORMAT_PPM,
198
FORMAT_JPEG,
199
FORMAT_PNG,
200
// Formats supported by opencv
201
FORMAT_TIFF,
202
FORMAT_BMP,
203
FORMAT_DIB,
204
FORMAT_PBM,
205
FORMAT_RASTER,
206
FORMAT_JPEG2000,
207
// Video format
208
FORMAT_AVI,
209
FORMAT_MPEG,
210
FORMAT_MPEG4,
211
FORMAT_MTS,
212
FORMAT_MOV,
213
FORMAT_OGV,
214
FORMAT_WMV,
215
FORMAT_FLV,
216
FORMAT_MKV,
217
FORMAT_UNKNOWN
218
} vpVideoFormatType;
219
221
vpVideoFormatType m_formatType;
222
224
std::string m_videoName;
225
std::string m_frameName;
227
bool
m_initFileName;
229
bool
m_isOpen;
231
long
m_frameCount;
// Index of the next image
233
long
m_firstFrame;
235
long
m_lastFrame;
236
bool
m_firstFrameIndexIsSet;
237
bool
m_lastFrameIndexIsSet;
239
long
m_frameStep;
240
double
m_frameRate;
241
242
public
:
243
vpVideoReader
();
244
vpVideoReader
(
const
vpVideoReader
&reader);
245
virtual
~vpVideoReader
() VP_OVERRIDE;
246
vpVideoReader
&
operator=
(
const
vpVideoReader
&reader);
247
248
void
acquire
(
vpImage<vpRGBa>
&I) VP_OVERRIDE;
249
void
acquire
(
vpImage<unsigned char>
&I) VP_OVERRIDE;
250
void
close
() VP_OVERRIDE { }
251
255
inline
bool
end
()
256
{
257
if
(m_frameStep > 0) {
258
if
(m_frameCount + m_frameStep > m_lastFrame)
259
return
true
;
260
}
261
else
if
(m_frameStep < 0) {
262
if
(m_frameCount + m_frameStep < m_firstFrame)
263
return
true
;
264
}
265
return
false
;
266
}
267
bool
getFrame(
vpImage<vpRGBa>
&I,
long
frame);
268
bool
getFrame(
vpImage<unsigned char>
&I,
long
frame);
269
275
double
getFramerate
()
276
{
277
if
(!m_isOpen) {
278
getProperties();
279
}
280
return
m_frameRate;
281
}
282
292
inline
long
getFrameIndex
()
const
{
return
m_frameCount; }
293
297
inline
std::string
getFrameName
()
const
{
return
m_frameName; }
298
304
inline
long
getFirstFrameIndex
()
305
{
306
if
(!m_isOpen) {
307
getProperties();
308
}
309
return
m_firstFrame;
310
}
311
317
inline
long
getLastFrameIndex
()
318
{
319
if
(!m_isOpen) {
320
getProperties();
321
}
322
return
m_lastFrame;
323
}
324
330
inline
long
getFrameStep
()
const
{
return
m_frameStep; }
331
332
bool
isVideoFormat()
const
;
333
void
open
(
vpImage<vpRGBa>
&I) VP_OVERRIDE;
334
void
open
(
vpImage<unsigned char>
&I) VP_OVERRIDE;
335
336
vpVideoReader
&operator>>(
vpImage<unsigned char>
&I);
337
vpVideoReader
&operator>>(
vpImage<vpRGBa>
&I);
338
347
inline
void
resetFrameCounter
() { m_frameCount = m_firstFrame; }
348
void
setFileName(
const
std::string &filename);
349
358
inline
void
setFirstFrameIndex
(
const
long
first_frame)
359
{
360
m_firstFrameIndexIsSet =
true
;
361
m_firstFrame = first_frame;
362
}
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
387
private
:
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
END_VISP_NAMESPACE
399
400
#endif
vpDiskGrabber
Class to grab (ie. read) images from the disk.
Definition
vpDiskGrabber.h:109
vpFrameGrabber::open
virtual void open(vpImage< unsigned char > &I)=0
vpFrameGrabber::operator=
vpFrameGrabber & operator=(const vpFrameGrabber &)=default
vpFrameGrabber::vpFrameGrabber
vpFrameGrabber()
Definition
vpFrameGrabber.h:114
vpFrameGrabber::acquire
virtual void acquire(vpImage< unsigned char > &I)=0
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpVideoReader
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
Definition
vpVideoReader.h:181
vpVideoReader::vpVideoReader
vpVideoReader()
Definition
vpVideoReader.cpp:51
vpVideoReader::setLastFrameIndex
void setLastFrameIndex(const long last_frame)
Definition
vpVideoReader.h:371
vpVideoReader::getLastFrameIndex
long getLastFrameIndex()
Definition
vpVideoReader.h:317
vpVideoReader::resetFrameCounter
void resetFrameCounter()
Definition
vpVideoReader.h:347
vpVideoReader::end
bool end()
Definition
vpVideoReader.h:255
vpVideoReader::setFirstFrameIndex
void setFirstFrameIndex(const long first_frame)
Definition
vpVideoReader.h:358
vpVideoReader::getFirstFrameIndex
long getFirstFrameIndex()
Definition
vpVideoReader.h:304
vpVideoReader::setFrameStep
void setFrameStep(const long frame_step)
Definition
vpVideoReader.h:385
vpVideoReader::close
void close() VP_OVERRIDE
Definition
vpVideoReader.h:250
vpVideoReader::getFrameStep
long getFrameStep() const
Definition
vpVideoReader.h:330
vpVideoReader::getFrameName
std::string getFrameName() const
Definition
vpVideoReader.h:297
vpVideoReader::getFramerate
double getFramerate()
Definition
vpVideoReader.h:275
vpVideoReader::getFrameIndex
long getFrameIndex() const
Definition
vpVideoReader.h:292
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
io
include
visp3
io
vpVideoReader.h
Generated by
1.17.0