Visual Servoing Platform
version 3.6.1 under development (2024-10-10)
|
#include <visp3/io/vpVideoReader.h>
Public Member Functions | |
vpVideoReader () | |
virtual | ~vpVideoReader () |
void | acquire (vpImage< vpRGBa > &I) |
void | acquire (vpImage< unsigned char > &I) |
void | close () |
bool | end () |
bool | getFrame (vpImage< vpRGBa > &I, long frame) |
bool | getFrame (vpImage< unsigned char > &I, long frame) |
double | getFramerate () |
long | getFrameIndex () const |
std::string | getFrameName () const |
long | getFirstFrameIndex () |
long | getLastFrameIndex () |
long | getFrameStep () const |
bool | isVideoFormat () const |
void | open (vpImage< vpRGBa > &I) |
void | open (vpImage< unsigned char > &I) |
vpVideoReader & | operator>> (vpImage< unsigned char > &I) |
vpVideoReader & | operator>> (vpImage< vpRGBa > &I) |
void | resetFrameCounter () |
void | setFileName (const std::string &filename) |
void | setFirstFrameIndex (const long first_frame) |
void | setLastFrameIndex (const long last_frame) |
void | setFrameStep (const long frame_step) |
Public Attributes | |
bool | init |
Inherited functionalities from vpFramegrabber | |
unsigned int | getHeight () const |
unsigned int | getWidth () const |
unsigned int | height |
unsigned int | width |
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.
This class has its own implementation to read a sequence of PGM and PPM images.
This class may benefit from optional 3rd parties:
The following example available in tutorial-video-reader.cpp shows how this class is really easy to use. It enables to read a video file named video.mpeg.
As shown in the next example, this class allows also to access to a specific frame. But be careful, for video files, the getFrame() method is not precise and returns the nearest intra 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.
The other following example explains how to use the class to read a sequence of images. The images are stored in the folder "./image" and are named "image0000.jpeg", "image0001.jpeg", "image0002.jpeg", ... As explained in setFirstFrameIndex() and setLastFrameIndex() it is also possible to set the first and last image numbers to read a portion of the sequence. If these two functions are not used, first and last image numbers are set automatically to match the first and image images of the sequence.
Note that it is also possible to access to a specific frame using getFrame().
Definition at line 178 of file vpVideoReader.h.
BEGIN_VISP_NAMESPACE vpVideoReader::vpVideoReader | ( | ) |
Basic constructor.
Definition at line 51 of file vpVideoReader.cpp.
|
virtual |
Basic destructor.
Definition at line 64 of file vpVideoReader.cpp.
|
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.
I | : The image where the frame is stored. |
Implements vpFrameGrabber.
Definition at line 337 of file vpVideoReader.cpp.
References vpDiskGrabber::acquire(), vpImageConvert::convert(), vpDiskGrabber::getImageName(), vpDiskGrabber::getImageNumber(), open(), vpDiskGrabber::setImageNumber(), and vpDiskGrabber::setStep().
Grabs the current (k) 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. If open() was not called previously, this method opens the video reader.
This method enables to use the class as frame grabber.
I | : The image where the frame is stored. |
Implements vpFrameGrabber.
Definition at line 243 of file vpVideoReader.cpp.
References vpDiskGrabber::acquire(), vpImageConvert::convert(), vpDiskGrabber::getImageName(), vpDiskGrabber::getImageNumber(), open(), vpDiskGrabber::setImageNumber(), setLastFrameIndex(), and vpDiskGrabber::setStep().
Referenced by operator>>().
|
inlinevirtual |
This virtual function is used to de-allocate the memory used by a specific frame grabber
Implements vpFrameGrabber.
Definition at line 244 of file vpVideoReader.h.
|
inline |
Definition at line 249 of file vpVideoReader.h.
|
inline |
Gets the first frame index.
Definition at line 298 of file vpVideoReader.h.
bool vpVideoReader::getFrame | ( | vpImage< unsigned char > & | I, |
long | frame_index | ||
) |
Gets the th frame and stores it in the image .
I | : The vpImage used to stored the frame. |
frame_index | : The index of the frame which has to be read. |
Definition at line 510 of file vpVideoReader.cpp.
References vpDiskGrabber::acquire(), vpImageConvert::convert(), vpImage< Type >::getHeight(), vpDiskGrabber::getImageNumber(), vpImage< Type >::getWidth(), vpFrameGrabber::height, vpDiskGrabber::setImageNumber(), setLastFrameIndex(), and vpFrameGrabber::width.
Gets the th frame and stores it in the image .
I | : The vpImage used to stored the frame. |
frame_index | : The index of the frame which has to be read. |
Definition at line 433 of file vpVideoReader.cpp.
References vpDiskGrabber::acquire(), vpImageConvert::convert(), vpImage< Type >::getHeight(), vpDiskGrabber::getImageNumber(), vpImage< Type >::getWidth(), vpFrameGrabber::height, vpDiskGrabber::setImageNumber(), setLastFrameIndex(), and vpFrameGrabber::width.
Referenced by open().
|
inline |
Get the frame index of the current image. 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()).
Definition at line 286 of file vpVideoReader.h.
|
inline |
Return the name of the file in which the last frame was read.
Definition at line 291 of file vpVideoReader.h.
|
inline |
Return the frame rate in Hz used to encode the video stream.
If the video is a sequence of images, return -1.
Definition at line 269 of file vpVideoReader.h.
|
inline |
Gets the frame step.
Definition at line 324 of file vpVideoReader.h.
|
inherited |
Return the number of rows in the image.
Definition at line 38 of file vpFrameGrabber.cpp.
References vpFrameGrabber::height.
|
inline |
Gets the last frame index.
Definition at line 311 of file vpVideoReader.h.
|
inherited |
Return the number of columns in the image.
Definition at line 43 of file vpFrameGrabber.cpp.
References vpFrameGrabber::width.
bool vpVideoReader::isVideoFormat | ( | ) | const |
Indicate if the video is an encoded single video file.
Definition at line 895 of file vpVideoReader.cpp.
|
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 | : The image where the frame is stored. |
Implements vpFrameGrabber.
Definition at line 207 of file vpVideoReader.cpp.
References getFrame(), and vpException::ioError.
Sets all the parameters needed to read the video or the image sequence.
Grab the first frame and stores it in the image .
I | : The image where the frame is stored. |
Implements vpFrameGrabber.
Definition at line 174 of file vpVideoReader.cpp.
References getFrame(), and vpException::ioError.
Referenced by acquire().
vpVideoReader & vpVideoReader::operator>> | ( | vpImage< unsigned char > & | I | ) |
Operator that allows to capture a grey level image.
I | : The captured image. |
Definition at line 830 of file vpVideoReader.cpp.
References acquire().
vpVideoReader & vpVideoReader::operator>> | ( | vpImage< vpRGBa > & | I | ) |
Operator that allows to capture a grey level image.
I | : The captured image. |
Definition at line 863 of file vpVideoReader.cpp.
References acquire().
|
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 the acquire method).
Definition at line 341 of file vpVideoReader.h.
void vpVideoReader::setFileName | ( | const std::string & | filename | ) |
It enables to set the path and the name of the video which has to be read.
If you want to read a video file, filename
corresponds to the path to the file (e.g.: /local/video.mpeg
).
If you want to read a sequence of images, filename
corresponds rather to the path followed by the image name template. For example, 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
.
filename | : Path to a video file or file name template of a image sequence. |
Definition at line 86 of file vpVideoReader.cpp.
References vpException::badValue, vpIoTools::getName(), and vpImageException::noFileNameError.
|
inline |
Enables to set the first frame index if you want to use the class like a grabber (ie with the acquire method).
first_frame | : The first frame index. |
Definition at line 352 of file vpVideoReader.h.
|
inline |
Sets the frame step index. The default frame step is 1
frame_step | : The frame index step. |
Definition at line 379 of file vpVideoReader.h.
|
inline |
Enables to set the last frame index.
last_frame | : The last frame index. |
Definition at line 365 of file vpVideoReader.h.
Referenced by acquire(), and getFrame().
|
protectedinherited |
Number of rows in the image.
Definition at line 134 of file vpFrameGrabber.h.
Referenced by vpDiskGrabber::acquire(), vpPylonGrabberGigE::acquire(), vpPylonGrabberUsb::acquire(), vpFlyCaptureGrabber::acquire(), vpV4l2Grabber::acquire(), vp1394TwoGrabber::acquire(), vp1394TwoGrabber::dequeue(), vpDirectShowGrabber::getFormat(), getFrame(), vpFrameGrabber::getHeight(), vp1394TwoGrabber::getHeight(), vpDiskGrabber::open(), vp1394CMUGrabber::open(), vpV4l2Grabber::open(), vpDirectShowGrabber::setFormat(), vp1394TwoGrabber::setFormat7ROI(), vpDirectShowGrabber::setImageSize(), vp1394CMUGrabber::setVideoMode(), vp1394TwoGrabber::setVideoMode(), vp1394CMUGrabber::vp1394CMUGrabber(), and vp1394TwoGrabber::vp1394TwoGrabber().
|
inherited |
Set to true if the frame grabber has been initialized.
Definition at line 102 of file vpFrameGrabber.h.
Referenced by vpV4l2Grabber::acquire(), vp1394CMUGrabber::close(), vp1394TwoGrabber::close(), vpFlyCaptureGrabber::connect(), vpPylonGrabberGigE::connect(), vpPylonGrabberUsb::connect(), vpFlyCaptureGrabber::disconnect(), vpPylonGrabberGigE::disconnect(), vpPylonGrabberUsb::disconnect(), vpDiskGrabber::open(), vpV4l2Grabber::open(), vp1394TwoGrabber::resetBus(), vpFlyCaptureGrabber::startCapture(), vpPylonGrabberGigE::startCapture(), vpPylonGrabberUsb::startCapture(), vpFlyCaptureGrabber::stopCapture(), vpPylonGrabberGigE::stopCapture(), vpPylonGrabberUsb::stopCapture(), vp1394CMUGrabber::vp1394CMUGrabber(), vp1394TwoGrabber::vp1394TwoGrabber(), vpDiskGrabber::vpDiskGrabber(), and vpV4l2Grabber::vpV4l2Grabber().
|
protectedinherited |
Number of columns in the image.
Definition at line 135 of file vpFrameGrabber.h.
Referenced by vpDiskGrabber::acquire(), vpPylonGrabberGigE::acquire(), vpPylonGrabberUsb::acquire(), vpFlyCaptureGrabber::acquire(), vpV4l2Grabber::acquire(), vp1394TwoGrabber::acquire(), vp1394TwoGrabber::dequeue(), vpDirectShowGrabber::getFormat(), getFrame(), vpFrameGrabber::getWidth(), vp1394TwoGrabber::getWidth(), vpDiskGrabber::open(), vp1394CMUGrabber::open(), vpV4l2Grabber::open(), vpDirectShowGrabber::setFormat(), vp1394TwoGrabber::setFormat7ROI(), vpDirectShowGrabber::setImageSize(), vp1394CMUGrabber::setVideoMode(), vp1394TwoGrabber::setVideoMode(), vp1394CMUGrabber::vp1394CMUGrabber(), and vp1394TwoGrabber::vp1394TwoGrabber().