ViSP  2.7.0
vpVideoReader Class Reference

#include <vpVideoReader.h>

+ Inheritance diagram for vpVideoReader:

Public Member Functions

 vpVideoReader ()
 
 ~vpVideoReader ()
 
void acquire (vpImage< vpRGBa > &I)
 
void acquire (vpImage< unsigned char > &I)
 
void close ()
 
bool getFrame (vpImage< vpRGBa > &I, long frame)
 
bool getFrame (vpImage< unsigned char > &I, long frame)
 
long getFrameIndex () const
 
long getLastFrameIndex () const
 
void open (vpImage< vpRGBa > &I)
 
void open (vpImage< unsigned char > &I)
 
void resetFrameCounter ()
 
void setFileName (const char *filename)
 
void setFileName (const std::string &filename)
 
void setFirstFrameIndex (const long firstFrame)
 
unsigned int getHeight () const
 
unsigned int getWidth () const
 

Public Attributes

bool init
 

Protected Attributes

unsigned int height
 
unsigned int width
 

Detailed Description

Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the vpFrameGrabber Class, it can be used like an other frame grabber class.

The following example shows how this class is really easy to use. It enable to read a video file named video.mpeg and located in the folder "./video".

But be careful, for video files, the getFrame method is not precise and returns the nearest key frame from the expected frame. You can use the getFrame method to position the reader in the video and then use the acquire method to get the following frames one by one.

#include <visp/vpConfig.h>
#include <visp/vpImage.h>
#include <visp/vpRGBa.h>
#include <visp/vpVideoReader.h>
#ifdef VISP_HAVE_FFMPEG
int main()
{
//Initialize the reader.
reader.setFileName("./video/video.mpeg");
reader.open(I);
//Read the nearest key frame from the 3th frame
reader.getFrame(I,2);
//After positionning the video reader use acquire to read the video frame by frame
reader.acquire(I);
return 0;
}
#else
int main() {}
#endif

The other following example explains how to use the class to manipulate a sequence of images. The images are stored in the folder "./image" and are named "image0000.jpeg", "image0001.jpeg", "image0002.jpeg", ...

#include <visp/vpConfig.h>
#include <visp/vpImage.h>
#include <visp/vpRGBa.h>
#include <visp/vpVideoReader.h>
int main()
{
//Initialize the reader.
reader.setFileName("./image/image%04d.jpeg");
reader.open(I);
//Read the 3th frame
reader.getFrame(I,2);
return 0;
}
Examples:
AROgre.cpp, AROgreBasic.cpp, imageSequenceReader.cpp, mbtEdgeKltTracking.cpp, mbtEdgeTracking.cpp, mbtKltTracking.cpp, trackMeNurbs.cpp, and videoReader.cpp.

Definition at line 123 of file vpVideoReader.h.

Constructor & Destructor Documentation

vpVideoReader::vpVideoReader ( )

Basic constructor.

Definition at line 57 of file vpVideoReader.cpp.

vpVideoReader::~vpVideoReader ( )

Basic destructor.

Definition at line 74 of file vpVideoReader.cpp.

Member Function Documentation

void vpVideoReader::acquire ( vpImage< vpRGBa > &  I)
virtual

Grabs the kth image in the stack of frames and increments the frame counter in order to grab the next image (k+1) during the next use of the method.

This method enables to use the class as frame grabber.

Parameters
I: The image where the frame is stored.

Implements vpFrameGrabber.

Examples:
AROgre.cpp, AROgreBasic.cpp, mbtEdgeKltTracking.cpp, mbtEdgeTracking.cpp, mbtKltTracking.cpp, and videoReader.cpp.

Definition at line 267 of file vpVideoReader.cpp.

References vpDiskGrabber::acquire(), vpFFMPEG::acquire(), vpException::notInitialized, and vpERROR_TRACE.

void vpVideoReader::acquire ( vpImage< unsigned char > &  I)
virtual

Grabs the kth image in the stack of frames and increments the frame counter in order to grab the next image (k+1) during the next use of the method.

This method enables to use the class as frame grabber.

Parameters
I: The image where the frame is stored.

Implements vpFrameGrabber.

Definition at line 294 of file vpVideoReader.cpp.

References vpDiskGrabber::acquire(), vpFFMPEG::acquire(), vpException::notInitialized, and vpERROR_TRACE.

void vpVideoReader::close ( )
inlinevirtual

This virtual function is used to de-allocate the memory used by a specific frame grabber

Implements vpFrameGrabber.

Examples:
AROgre.cpp, AROgreBasic.cpp, mbtEdgeKltTracking.cpp, mbtEdgeTracking.cpp, and mbtKltTracking.cpp.

Definition at line 168 of file vpVideoReader.h.

bool vpVideoReader::getFrame ( vpImage< vpRGBa > &  I,
long  frame 
)

Gets the $ frame $ th frame and stores it in the image $ I $.

Warning
For the video files this method is not precise, and returns the nearest key frame from the expected frame. But this method enables to postion the reader where you want. Then, use the acquire method to grab the following images one after one.
Parameters
I: The vpImage used to stored the frame.
frame: The index of the frame which has to be read.
Returns
It returns true if the frame could be read. Else it returns false.
Examples:
imageSequenceReader.cpp, trackMeNurbs.cpp, and videoReader.cpp.

Definition at line 326 of file vpVideoReader.cpp.

References vpDiskGrabber::acquire(), vpFFMPEG::getFrame(), and vpERROR_TRACE.

Referenced by open().

bool vpVideoReader::getFrame ( vpImage< unsigned char > &  I,
long  frame 
)

Gets the $ frame $ th frame and stores it in the image $ I $.

Warning
For the video files this method is not precise, and returns the nearest key frame from the expected frame. But this method enables to postion the reader where you want. Then, use the acquire method to grab the following images one after one.
Parameters
I: The vpImage used to stored the frame.
frame: The index of the frame which has to be read.
Returns
It returns true if the frame could be read. Else it returns false.

Definition at line 367 of file vpVideoReader.cpp.

References vpDiskGrabber::acquire(), vpFFMPEG::getFrame(), and vpERROR_TRACE.

long vpVideoReader::getFrameIndex ( ) const
inline

Get the current frame index. This index is updated at each call of the acquire method. It can be used to detect the end of a file (comparison with getLastFrameIndex()).

Returns
Returns the current frame index.

Definition at line 179 of file vpVideoReader.h.

unsigned int vpFrameGrabber::getHeight ( ) const
inlineinherited

Return the number of rows in the image.

Examples:
AROgre.cpp, AROgreBasic.cpp, HelloWorldOgre.cpp, and HelloWorldOgreAdvanced.cpp.

Definition at line 119 of file vpFrameGrabber.h.

Referenced by vp1394Grabber::acquire(), and vp1394Grabber::open().

long vpVideoReader::getLastFrameIndex ( ) const
inline

Gets the last frame index.

Returns
Returns the last frame index.
Examples:
imageSequenceReader.cpp, and videoReader.cpp.

Definition at line 186 of file vpVideoReader.h.

unsigned int vpFrameGrabber::getWidth ( ) const
inlineinherited

Return the number of columns in the image.

Examples:
AROgre.cpp, AROgreBasic.cpp, HelloWorldOgre.cpp, and HelloWorldOgreAdvanced.cpp.

Definition at line 121 of file vpFrameGrabber.h.

Referenced by vp1394Grabber::acquire(), and vp1394Grabber::open().

void vpVideoReader::open ( vpImage< vpRGBa > &  I)
virtual
void vpVideoReader::open ( vpImage< unsigned char > &  I)
virtual

Sets all the parameters needed to read the video or the image sequence.

Grab the first frame and stores it in the image $ I $.

Parameters
I: The image where the frame is stored.

Implements vpFrameGrabber.

Definition at line 201 of file vpVideoReader.cpp.

References vpException::fatalError, getFrame(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpFFMPEG::GRAY_SCALED, vpFrameGrabber::height, vpFFMPEG::initStream(), vpException::ioError, vpImageException::noFileNameError, vpFFMPEG::openStream(), vpDiskGrabber::setGenericName(), vpDiskGrabber::setImageNumber(), vpERROR_TRACE, and vpFrameGrabber::width.

void vpVideoReader::resetFrameCounter ( )
inline

Reset the frame counter and sets it to the first image index.

By default the first frame index is set to 0.

This method is useful if you use the class like a frame grabber (ie with theacquire method).

Definition at line 197 of file vpVideoReader.h.

void vpVideoReader::setFileName ( const char *  filename)

It enables to set the path and the name of the file(s) which as/have to be read.

If you want to read a video file, $ filename $ corresponds to the path to the file (example : /local/video.mpeg).

If you want to read a sequence of images, $ filename $ corresponds to the path followed by the image name template. For exemple, if you want to read different images named image0001.jpeg, image0002.jpg, ... and located in the folder /local/image, $ filename $ will be "/local/image/image%04d.jpg".

Parameters
filename: Path to a video file or file name template of a image sequence.
Examples:
AROgre.cpp, AROgreBasic.cpp, imageSequenceReader.cpp, mbtEdgeKltTracking.cpp, mbtEdgeTracking.cpp, mbtKltTracking.cpp, trackMeNurbs.cpp, and videoReader.cpp.

Definition at line 98 of file vpVideoReader.cpp.

References vpImageException::noFileNameError, and vpERROR_TRACE.

Referenced by setFileName().

void vpVideoReader::setFileName ( const std::string &  filename)

It enables to set the path and the name of the file(s) which as/have to be read.

If you want to read a video file, $ filename $ corresponds to the path to the file (example : /local/video.mpeg).

If you want to read a sequence of images, $ filename $ corresponds to the path followed by the image name template. For exemple, if you want to read different images named image0001.jpeg, image0002.jpg, ... and located in the folder /local/image, $ filename $ will be "/local/image/image%04d.jpg".

Parameters
filename: Path to a video file or file name template of a image sequence.

Definition at line 122 of file vpVideoReader.cpp.

References setFileName().

void vpVideoReader::setFirstFrameIndex ( const long  firstFrame)
inline

Enables to set the first frame index if you want to use the class like a grabber (ie with the acquire method).

Parameters
firstFrame: The first frame index.
Examples:
AROgre.cpp, AROgreBasic.cpp, imageSequenceReader.cpp, and trackMeNurbs.cpp.

Definition at line 206 of file vpVideoReader.h.

Member Data Documentation