Definition and access functions for video4linux frame grabber. More...
#include <Devices/V4Lgrabber.H>
Public Member Functions | |
V4Lgrabber (OptionManager &mgr, const std::string &descrName="V4L Frame Grabber Driver", const std::string &tagName="V4LFrameGrabber", const ParamFlag flags=USE_MY_VAL) | |
Constructor. | |
virtual | ~V4Lgrabber () |
Destructor. | |
virtual void | setListener (rutz::shared_ptr< FrameListener > listener) |
Install a FrameListener. | |
virtual void | startStream () |
Get a streaming grab started. | |
virtual GenericFrameSpec | peekFrameSpec () |
Return the specifications of the next frame to be returned. | |
virtual SimTime | getNaturalFrameTime () const |
Get the inter-frame time that matches our video mode. | |
virtual GenericFrame | readFrame () |
Get the next frame from the frame-grabber. | |
Protected Member Functions | |
VideoFrame | grabRaw () |
Grab a raw VideoFrame. | |
VideoFrame | grabSingleRaw () |
Grab a single VideoFrame. | |
virtual void | start1 () |
get started | |
virtual void | stop2 () |
get stopped |
Definition and access functions for video4linux frame grabber.
This class provides a trivial interface to Video4Linux frame grabbers. All the low-level setup is done during construction. The user only needs to call readRGB() or readFrame() to capture an image. Shared memory and DMA directly from the grabber hardware into our memory is used if supported by the grabber and driver. This should work with any framegrabber that is supported by Video4Linux. We use Bt878-based boards.
After each grab, the next grab is initiated, and will be ready 33ms later (or one frame later if not NTSC). If you call readFrame() again before 33ms have elapsed, it will block until the next frame is available. If you call it too late, you will have missed the latest frame, and readFrame() will block until the next frame is acquired.
So a good strategy is to use readFrame() to not only grab but also to synchronize your code with the video rate (30 frames/s if NTSC). Typically, then, you would have a main loop that first grabs and then does various processing that is guaranteed to take less than 33ms. You do not need to insert any pause after that processing to obtain a stable framerate; just finish your main loop, and the next call to readFrame() (at the next iteration) will block until exactly one frame has passed since it was last called. See how this is done, for example, in pvisionTCP-master.C or test-grab.C
Definition at line 87 of file V4Lgrabber.H.
V4Lgrabber::V4Lgrabber | ( | OptionManager & | mgr, | |
const std::string & | descrName = "V4L Frame Grabber Driver" , |
|||
const std::string & | tagName = "V4LFrameGrabber" , |
|||
const ParamFlag | flags = USE_MY_VAL | |||
) |
Constructor.
Definition at line 99 of file V4Lgrabber.C.
References OptionManager::requestOptionAlias().
V4Lgrabber::~V4Lgrabber | ( | ) | [virtual] |
Destructor.
Definition at line 337 of file V4Lgrabber.C.
SimTime V4Lgrabber::getNaturalFrameTime | ( | ) | const [virtual] |
Get the inter-frame time that matches our video mode.
Reimplemented from FrameIstream.
Definition at line 357 of file V4Lgrabber.C.
VideoFrame V4Lgrabber::grabRaw | ( | ) | [protected] |
Grab a raw VideoFrame.
Don't call this directly; use readFrame() instead.
Definition at line 391 of file V4Lgrabber.C.
References ASSERT, Image< T >::getArrayPtr(), Image< T >::getSize(), OModelParam< T >::getVal(), and Image< T >::initialized().
Referenced by readFrame().
VideoFrame V4Lgrabber::grabSingleRaw | ( | ) | [protected] |
Grab a single VideoFrame.
Don't call this directly; use readFrame() instead.
This function will work better with single-shot grabs (as opposed to video) and USB cameras.
Definition at line 484 of file V4Lgrabber.C.
References ASSERT, Image< T >::getArrayPtr(), Image< T >::getSize(), OModelParam< T >::getVal(), and Image< T >::initialized().
Referenced by readFrame().
GenericFrameSpec V4Lgrabber::peekFrameSpec | ( | ) | [virtual] |
Return the specifications of the next frame to be returned.
Implements FrameIstream.
Definition at line 363 of file V4Lgrabber.C.
References OModelParam< T >::getVal().
GenericFrame V4Lgrabber::readFrame | ( | ) | [virtual] |
Get the next frame from the frame-grabber.
Returns grabbed frame. This call will block until a frame is ready and has been grabbed.
Beware that the integrity of the GenericFrame object may not last "very long"; basically, try to be finished using the GenericFrame object before you attempt to grab the next frame in the stream. If you need it for longer than that, then you should use GenericFrame::deepCopyOf() to make a copy of the frame that can be safely held indefinitely.
Implements FrameIstream.
Definition at line 377 of file V4Lgrabber.C.
References rutz::shared_ptr< T >::get(), OModelParam< T >::getVal(), grabRaw(), and grabSingleRaw().
void V4Lgrabber::setListener | ( | rutz::shared_ptr< FrameListener > | listener | ) | [virtual] |
Install a FrameListener.
We call the listener's onRawFrame() inside each readFrame().
Reimplemented from FrameIstream.
Definition at line 341 of file V4Lgrabber.C.
void V4Lgrabber::start1 | ( | ) | [protected, virtual] |
get started
Reimplemented from ModelComponent.
Definition at line 135 of file V4Lgrabber.C.
References getFrameSize(), OModelParam< T >::getVal(), Dims::h(), SimTime::HERTZ(), NO_INIT, OModelParam< T >::setVal(), Dims::w(), and SimTime::ZERO().
void V4Lgrabber::startStream | ( | ) | [virtual] |
Get a streaming grab started.
This will instruct the grabber to grab all of its possible buffers, one after the other. Typically you should call this just before you start reading frames. If the option --framegrabber-streaming=false is set, then this call is a (safe) no-op.
Reimplemented from FrameIstream.
Definition at line 347 of file V4Lgrabber.C.
void V4Lgrabber::stop2 | ( | ) | [protected, virtual] |