Visual Servoing Platform
version 3.0.1
|
#include <visp3/sensor/vpV4l2Grabber.h>
Public Types | |
enum | vpV4l2FramerateType { framerate_50fps, framerate_25fps } |
enum | vpV4l2FrameFormatType { V4L2_FRAME_FORMAT, V4L2_IMAGE_FORMAT } |
enum | vpV4l2PixelFormatType { V4L2_GREY_FORMAT, V4L2_RGB24_FORMAT, V4L2_RGB32_FORMAT, V4L2_BGR24_FORMAT, V4L2_YUYV_FORMAT, V4L2_MAX_FORMAT } |
Public Member Functions | |
vpV4l2Grabber () | |
vpV4l2Grabber (bool verbose) | |
vpV4l2Grabber (unsigned input, unsigned scale=vpV4l2Grabber::DEFAULT_SCALE) | |
vpV4l2Grabber (vpImage< unsigned char > &I, unsigned input, unsigned scale=vpV4l2Grabber::DEFAULT_SCALE) | |
vpV4l2Grabber (vpImage< vpRGBa > &I, unsigned input, unsigned scale=vpV4l2Grabber::DEFAULT_SCALE) | |
virtual | ~vpV4l2Grabber () |
void | open (vpImage< unsigned char > &I) |
void | open (vpImage< vpRGBa > &I) |
void | acquire (vpImage< unsigned char > &I) |
void | acquire (vpImage< unsigned char > &I, const vpRect &roi) |
void | acquire (vpImage< unsigned char > &I, struct timeval ×tamp, const vpRect &roi=vpRect()) |
void | acquire (vpImage< vpRGBa > &I) |
void | acquire (vpImage< vpRGBa > &I, const vpRect &roi) |
void | acquire (vpImage< vpRGBa > &I, struct timeval ×tamp, const vpRect &roi=vpRect()) |
bool | getField () |
vpV4l2FramerateType | getFramerate () |
vpV4l2PixelFormatType | getPixelFormat () |
vpV4l2Grabber & | operator>> (vpImage< unsigned char > &I) |
vpV4l2Grabber & | operator>> (vpImage< vpRGBa > &I) |
void | setVerboseMode (bool verbose) |
void | setFramerate (vpV4l2FramerateType framerate) |
void | setInput (unsigned input=vpV4l2Grabber::DEFAULT_INPUT) |
void | setWidth (unsigned w) |
void | setHeight (unsigned h) |
void | setScale (unsigned scale=vpV4l2Grabber::DEFAULT_SCALE) |
void | setNBuffers (unsigned nbuffers) |
void | setDevice (const std::string &devname) |
void | setPixelFormat (vpV4l2PixelFormatType pixelformat) |
void | close () |
Inherited functionalities from vpFramegrabber | |
unsigned int | getHeight () const |
unsigned int | getWidth () const |
Public Attributes | |
bool | init |
Static Public Attributes | |
static const unsigned int | DEFAULT_INPUT = 2 |
static const unsigned int | DEFAULT_SCALE = 2 |
static const __u32 | MAX_INPUTS = 16 |
static const __u32 | MAX_NORM = 16 |
static const __u32 | MAX_FORMAT = 32 |
static const unsigned int | MAX_CTRL = 32 |
static const unsigned int | MAX_BUFFERS = 32 |
static const unsigned int | FRAME_SIZE = 288 |
Protected Attributes | |
unsigned int | height |
unsigned int | width |
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
Thus to be enabled, this class needs the optional V4L2 3rd party. Installation instruction are provided here https://visp.inria.fr/3rd_v4l2.
Information about Video4Linux can be found on http://linuxtv.org/v4lwiki/index.php/Main_Page
This class was tested with a Pinnacle PCTV Studio/Rave board but also with the following webcams (Logitech QuickCam Vision Pro 9000, Logitech QuickCam Orbit AF, Logitech QuickCam IM (V-USB39), Dell latitude E6400 internal webcam).
If the grabbing fail with a webcam, it means probably that you don't have the read/write permission on the /dev/video%d device. You can set the right permissions by "sudo chmod a+rw /dev/video*".
If the grabbing fails when the camera is attached to a bttv PCI card, it means potentially that you have not configured the linux bttv kernel module according to your board.
For that, depending on your linux distribution check the card id in
For example, the card id of a Pinnacle PCTV Studio/Rave board is 39. Once this id is determined, you have to set the bttv driver with, by adding
options bttv card=39
in one of theses files :
This first example available in tutorial-grabber-v4l2.cpp shows how to grab and display images from an usb camera.
This other example shows how to use this grabber with an analogic camera attached to a bttv PCI card.
Definition at line 134 of file vpV4l2Grabber.h.
Frame format type for capture.
Enumerator | |
---|---|
V4L2_FRAME_FORMAT |
a field only |
V4L2_IMAGE_FORMAT |
an interlaced image |
Definition at line 158 of file vpV4l2Grabber.h.
Frame rate type for capture.
Enumerator | |
---|---|
framerate_50fps |
50 frames per second |
framerate_25fps |
25 frames per second |
Definition at line 149 of file vpV4l2Grabber.h.
Pixel format type for capture.
Enumerator | |
---|---|
V4L2_GREY_FORMAT |
8 Greyscale |
V4L2_RGB24_FORMAT |
24 RGB-8-8-8 |
V4L2_RGB32_FORMAT |
32 RGB-8-8-8-8 |
V4L2_BGR24_FORMAT |
24 BGR-8-8-8 |
V4L2_YUYV_FORMAT |
16 YUYV 4:2:2 |
V4L2_MAX_FORMAT |
Definition at line 167 of file vpV4l2Grabber.h.
vpV4l2Grabber::vpV4l2Grabber | ( | ) |
Default constructor.
Setup the Video For Linux Two (V4L2) driver in streaming mode.
Default settings are:
The grabber allows also to grab a portion of an image using a region of interest. The following example shows how to grab a 320x240 region located on the top/left corner of the image that has a higher resolution (ie 640x480).
Definition at line 149 of file vpV4l2Grabber.cpp.
References DEFAULT_INPUT, DEFAULT_SCALE, framerate_25fps, vpFrameGrabber::init, setDevice(), setFramerate(), setInput(), setNBuffers(), setPixelFormat(), setScale(), and V4L2_YUYV_FORMAT.
vpV4l2Grabber::vpV4l2Grabber | ( | bool | verbose | ) |
Default constructor.
Setup the Video For Linux Two (V4L2) driver in streaming mode.
verbose | : If true activates the verbose mode. |
Default settings are:
Definition at line 208 of file vpV4l2Grabber.cpp.
References DEFAULT_INPUT, DEFAULT_SCALE, framerate_25fps, vpFrameGrabber::init, setDevice(), setFramerate(), setInput(), setNBuffers(), setPixelFormat(), setScale(), and V4L2_YUYV_FORMAT.
vpV4l2Grabber::vpV4l2Grabber | ( | unsigned | input, |
unsigned | scale = vpV4l2Grabber::DEFAULT_SCALE |
||
) |
Constructor.
Setup the Video For Linux Two (V4L2) driver in streaming mode.
input | : Video input port. |
scale | : Decimation factor. |
Default settings are:
Definition at line 258 of file vpV4l2Grabber.cpp.
References framerate_25fps, vpFrameGrabber::init, setDevice(), setFramerate(), setInput(), setNBuffers(), and setScale().
vpV4l2Grabber::vpV4l2Grabber | ( | vpImage< unsigned char > & | I, |
unsigned | input, | ||
unsigned | scale = vpV4l2Grabber::DEFAULT_SCALE |
||
) |
Constructor.
Setup the Video For Linux Two (V4L2) driver in streaming mode.
I | : Image data structure (grey 8 bits image) |
input | : Video input port. |
scale | : Decimation factor. |
Default settings are:
Definition at line 307 of file vpV4l2Grabber.cpp.
References framerate_25fps, vpFrameGrabber::init, open(), setDevice(), setFramerate(), setInput(), setNBuffers(), and setScale().
vpV4l2Grabber::vpV4l2Grabber | ( | vpImage< vpRGBa > & | I, |
unsigned | input, | ||
unsigned | scale = vpV4l2Grabber::DEFAULT_SCALE |
||
) |
Constructor.
Setup the Video For Linux Two (V4L2) driver in streaming mode.
I | : Image data structure (Color RGB32 bits image) |
input | : Video input port. |
scale | : Decimation factor. |
Default settings are:
Definition at line 359 of file vpV4l2Grabber.cpp.
References framerate_25fps, vpFrameGrabber::init, open(), setDevice(), setFramerate(), setInput(), setNBuffers(), and setScale().
|
virtual |
|
virtual |
Acquire a grey level image.
I | : Image data structure (8 bits image) |
vpFrameGrabberException::initializationError | : Frame grabber not initialized. |
Implements vpFrameGrabber.
Definition at line 568 of file vpV4l2Grabber.cpp.
Referenced by acquire(), and operator>>().
Acquire a grey level image.
I | : Image data structure (8 bits image) |
roi | : Region of interest to grab from the full resolution image. |
vpFrameGrabberException::initializationError | : Frame grabber not initialized. |
Definition at line 588 of file vpV4l2Grabber.cpp.
References acquire().
void vpV4l2Grabber::acquire | ( | vpImage< unsigned char > & | I, |
struct timeval & | timestamp, | ||
const vpRect & | roi = vpRect() |
||
) |
Acquire a grey level image.
I | : Image data structure (8 bits image). |
timestamp | : Timeval data structure providing the unix time at which the frame was captured in the ringbuffer. Warning: some v4l2 drivers do not return the time since 1970 (the one returned by gettimeofday() or vpTime) but rather a time that counts from the boot time (i.e. uptime). |
roi | : Region of interest to grab from the full resolution image. By default acquire the whole image. |
vpFrameGrabberException::initializationError | : Frame grabber not initialized. |
Definition at line 613 of file vpV4l2Grabber.cpp.
References vpImageConvert::BGRToGrey(), vpImage< Type >::bitmap, close(), vpImageTools::crop(), vpRect::getHeight(), vpRect::getWidth(), vpFrameGrabber::height, vpFrameGrabber::init, vpFrameGrabberException::initializationError, open(), vpImage< Type >::resize(), vpImageConvert::RGBaToGrey(), vpImageConvert::RGBToGrey(), V4L2_BGR24_FORMAT, V4L2_GREY_FORMAT, V4L2_RGB24_FORMAT, V4L2_RGB32_FORMAT, V4L2_YUYV_FORMAT, vpFrameGrabber::width, and vpImageConvert::YUYVToGrey().
Acquire a color image.
I | : Image data structure (32 bits image) |
vpFrameGrabberException::initializationError | : Frame grabber not initialized. |
Implements vpFrameGrabber.
Definition at line 698 of file vpV4l2Grabber.cpp.
References acquire().
Acquire a color image.
I | : Image data structure (32 bits image) |
roi | : Region of interest to grab from the full resolution image. |
vpFrameGrabberException::initializationError | : Frame grabber not initialized. |
Definition at line 718 of file vpV4l2Grabber.cpp.
References acquire().
void vpV4l2Grabber::acquire | ( | vpImage< vpRGBa > & | I, |
struct timeval & | timestamp, | ||
const vpRect & | roi = vpRect() |
||
) |
Acquire a color image.
I | : Image data structure (32 bits image). |
timestamp | : Timeval data structure providing the unix time at which the frame was captured in the ringbuffer. Warning: some v4l2 drivers do not return the time since 1970 (the one returned by gettimeofday() or vpTime) but rather a time that counts from the boot time (i.e. uptime). |
roi | : Region of interest to grab from the full resolution image. By default acquire the whole image. |
vpFrameGrabberException::initializationError | : Frame grabber not initialized. |
Definition at line 743 of file vpV4l2Grabber.cpp.
References vpImageConvert::BGRToRGBa(), vpImage< Type >::bitmap, close(), vpImageTools::crop(), vpRect::getHeight(), vpImage< Type >::getHeight(), vpRect::getLeft(), vpRect::getTop(), vpRect::getWidth(), vpImage< Type >::getWidth(), vpImageConvert::GreyToRGBa(), vpFrameGrabber::height, vpFrameGrabber::init, vpFrameGrabberException::initializationError, open(), vpImage< Type >::resize(), vpImageConvert::RGBToRGBa(), V4L2_BGR24_FORMAT, V4L2_GREY_FORMAT, V4L2_RGB24_FORMAT, V4L2_RGB32_FORMAT, V4L2_YUYV_FORMAT, vpFrameGrabber::width, and vpImageConvert::YUYVToRGBa().
|
virtual |
Close the video device.
Implements vpFrameGrabber.
Definition at line 898 of file vpV4l2Grabber.cpp.
Referenced by acquire(), getField(), open(), setScale(), and ~vpV4l2Grabber().
bool vpV4l2Grabber::getField | ( | ) |
Return the field (odd or even) corresponding to the last acquired frame.
This method is to call after acquire() and has only a mean if the acquisition framerate is set to 50 fps.
vpFrameGrabberException::otherError | : Video device returns a bad frame field. |
Definition at line 840 of file vpV4l2Grabber.cpp.
References close(), and vpFrameGrabberException::otherError.
vpV4l2Grabber::vpV4l2FramerateType vpV4l2Grabber::getFramerate | ( | ) |
Return the framerate of the acquisition.
Definition at line 888 of file vpV4l2Grabber.cpp.
|
inlineinherited |
Return the number of rows in the image.
Definition at line 115 of file vpFrameGrabber.h.
|
inline |
Get the pixel format used for capture.
Definition at line 241 of file vpV4l2Grabber.h.
Referenced by open().
|
inlineinherited |
Return the number of columns in the image.
Definition at line 117 of file vpFrameGrabber.h.
|
virtual |
Initialize image acquisition in grey format. Set the pixel format acquisition to vpV4l2Grabber::V4L2_GREY_FORMAT.
I | : Image data structure (8 bits image). Once the device is open, the image is resized to the current acquisition size. |
vpFrameGrabberException::settingError | : Wrong input channel. |
Implements vpFrameGrabber.
Definition at line 437 of file vpV4l2Grabber.cpp.
References close(), getPixelFormat(), vpFrameGrabber::height, vpFrameGrabber::init, open(), vpImage< Type >::resize(), setPixelFormat(), vpFrameGrabberException::settingError, V4L2_MAX_FORMAT, and vpFrameGrabber::width.
Referenced by acquire(), open(), and vpV4l2Grabber().
Initialize image acquisition in color RGB32 format. Set the pixel format acquisition to vpV4l2Grabber::V4L2_RGB32_FORMAT.
I | : Image data structure (RGB32 bits image). Once the device is open, the image is resized to the current acquisition size. |
Implements vpFrameGrabber.
Definition at line 505 of file vpV4l2Grabber.cpp.
References getPixelFormat(), vpFrameGrabber::height, vpFrameGrabber::init, open(), vpImage< Type >::resize(), setPixelFormat(), V4L2_MAX_FORMAT, and vpFrameGrabber::width.
vpV4l2Grabber & vpV4l2Grabber::operator>> | ( | vpImage< unsigned char > & | I | ) |
Operator that allows to capture a grey level image.
I | : The captured image. |
Definition at line 1514 of file vpV4l2Grabber.cpp.
References acquire().
vpV4l2Grabber & vpV4l2Grabber::operator>> | ( | vpImage< vpRGBa > & | I | ) |
Operator that allows to capture a grey level image.
I | : The captured image. |
Definition at line 1536 of file vpV4l2Grabber.cpp.
References acquire().
|
inline |
Set the device name.
devname | : Device name (like /dev/video0). |
Definition at line 301 of file vpV4l2Grabber.h.
Referenced by vpV4l2Grabber().
void vpV4l2Grabber::setFramerate | ( | vpV4l2Grabber::vpV4l2FramerateType | framerate | ) |
Set the frame format depending on the framerate acquisition.
framerate | : The framerate for the acquisition. |
Definition at line 867 of file vpV4l2Grabber.cpp.
References framerate_25fps, V4L2_FRAME_FORMAT, and V4L2_IMAGE_FORMAT.
Referenced by vpV4l2Grabber().
|
inline |
Set image height to acquire.
Definition at line 272 of file vpV4l2Grabber.h.
Referenced by setScale().
void vpV4l2Grabber::setInput | ( | unsigned | input = vpV4l2Grabber::DEFAULT_INPUT | ) |
Set the video input port on the board.
Definition at line 393 of file vpV4l2Grabber.cpp.
Referenced by vpV4l2Grabber().
|
inline |
Set the number of buffers required for streaming data.
For non real-time applications the number of buffers should be set to 1. For real-time applications to reach 25 fps or 50 fps a good compromise is to set the number of buffers to 3.
nbuffers | : Number of ring buffers. |
Definition at line 290 of file vpV4l2Grabber.h.
Referenced by vpV4l2Grabber().
|
inline |
Set the pixel format for capture.`If the specified pixel format is out of range, we set the V4L2_RGB24_FORMAT.
pixelformat | : Camera pixel format coding. |
Definition at line 313 of file vpV4l2Grabber.h.
Referenced by open(), and vpV4l2Grabber().
void vpV4l2Grabber::setScale | ( | unsigned | scale = vpV4l2Grabber::DEFAULT_SCALE | ) |
Set the decimation factor applied to full resolution images (768x576).
vpFrameGrabberException::settingError | : Wrong scale (should be between 1 and 16). |
scale | : Decimation factor. If scale is set to 2, 384x288 images will be acquired. |
An other way to specify the image size is to use setWidth() and setHeight().
Definition at line 411 of file vpV4l2Grabber.cpp.
References close(), setHeight(), vpFrameGrabberException::settingError, setWidth(), and vpERROR_TRACE.
Referenced by vpV4l2Grabber().
|
inline |
Activates the verbose mode to print additional information on stdout.
verbose | : If true activates the verbose mode. |
Definition at line 253 of file vpV4l2Grabber.h.
|
inline |
Set image width to acquire.
Definition at line 264 of file vpV4l2Grabber.h.
Referenced by setScale().
|
static |
Definition at line 137 of file vpV4l2Grabber.h.
Referenced by vpV4l2Grabber().
|
static |
Definition at line 138 of file vpV4l2Grabber.h.
Referenced by vpV4l2Grabber().
|
static |
Definition at line 144 of file vpV4l2Grabber.h.
|
protectedinherited |
Number of rows in the image.
Definition at line 108 of file vpFrameGrabber.h.
Referenced by vpDiskGrabber::acquire(), vpFlyCaptureGrabber::acquire(), acquire(), vp1394TwoGrabber::acquire(), vp1394TwoGrabber::dequeue(), vp1394TwoGrabber::getHeight(), vpDiskGrabber::open(), open(), vp1394CMUGrabber::open(), vpVideoReader::open(), vp1394TwoGrabber::setFormat7ROI(), vp1394CMUGrabber::setVideoMode(), vp1394TwoGrabber::setVideoMode(), vp1394CMUGrabber::vp1394CMUGrabber(), and vp1394TwoGrabber::vp1394TwoGrabber().
|
inherited |
Set to true if the frame grabber has been initialized.
Definition at line 105 of file vpFrameGrabber.h.
Referenced by acquire(), vp1394CMUGrabber::close(), vp1394TwoGrabber::close(), vpFlyCaptureGrabber::connect(), vpFlyCaptureGrabber::disconnect(), vpDiskGrabber::open(), open(), vp1394TwoGrabber::resetBus(), vpFlyCaptureGrabber::startCapture(), vpFlyCaptureGrabber::stopCapture(), vp1394CMUGrabber::vp1394CMUGrabber(), vp1394TwoGrabber::vp1394TwoGrabber(), vpDiskGrabber::vpDiskGrabber(), and vpV4l2Grabber().
|
static |
Definition at line 143 of file vpV4l2Grabber.h.
|
static |
Definition at line 142 of file vpV4l2Grabber.h.
|
static |
Definition at line 141 of file vpV4l2Grabber.h.
|
static |
Definition at line 139 of file vpV4l2Grabber.h.
|
static |
Definition at line 140 of file vpV4l2Grabber.h.
|
protectedinherited |
Number of columns in the image.
Definition at line 109 of file vpFrameGrabber.h.
Referenced by vpDiskGrabber::acquire(), vpFlyCaptureGrabber::acquire(), acquire(), vp1394TwoGrabber::acquire(), vp1394TwoGrabber::dequeue(), vp1394TwoGrabber::getWidth(), vpDiskGrabber::open(), open(), vp1394CMUGrabber::open(), vpVideoReader::open(), vp1394TwoGrabber::setFormat7ROI(), vp1394CMUGrabber::setVideoMode(), vp1394TwoGrabber::setVideoMode(), vp1394CMUGrabber::vp1394CMUGrabber(), and vp1394TwoGrabber::vp1394TwoGrabber().