V4L2Camera Class Reference

Video4Linux 2 camera access implementation. More...

#include <cams/v4l2.h>

Inheritance diagram for V4L2Camera:

List of all members.


Classes

struct  ControlParameterInt
struct  FrameBuffer

Public Member Functions

 V4L2Camera (const char *device_name="/dev/video0")
 Constructor.
 V4L2Camera (const CameraArgumentParser *cap)
 Constructor.
virtual ~V4L2Camera ()
 Destructor.
virtual void open ()
 Open the camera.
virtual void start ()
 Start image transfer from the camera.
virtual void stop ()
 Stop image transfer from the camera.
virtual void close ()
 Close camera.
virtual void flush ()
 Flush image queue.
virtual void capture ()
 Capture an image.
virtual void print_info ()
 Print out camera information.
virtual bool ready ()
 Camera is ready for taking pictures.
virtual unsigned char * buffer ()
 Get access to current image buffer.
virtual unsigned int buffer_size ()
 Size of buffer.
virtual void dispose_buffer ()
 Dispose current buffer.
virtual unsigned int pixel_width ()
 Width of image in pixels.
virtual unsigned int pixel_height ()
 Height of image in pixels.
virtual colorspace_t colorspace ()
 Colorspace of returned image.
virtual fawkes::Timecapture_time ()
 Get the Time of the last successfully captured image.
virtual void set_image_number (unsigned int n)
 Set image number to retrieve.
virtual bool auto_gain ()
 Return whether auto gain is enabled.
virtual void set_auto_gain (bool enabled)
 Enable/disable auto gain.
virtual bool auto_white_balance ()
 Return whether auto white balance is enabled.
virtual void set_auto_white_balance (bool enabled)
 Enable/disable auto white balance.
virtual bool auto_exposure ()
 Return whether auto exposure is enabled.
virtual void set_auto_exposure (bool enabled)
 Enable/disable auto exposure.
virtual int red_balance ()
 Get current red balance.
virtual void set_red_balance (int red_balance)
 Set red balance.
virtual int blue_balance ()
 Get current blue balance.
virtual void set_blue_balance (int blue_balance)
 Set blue balance.
virtual int u_balance ()
 Get current u balance.
virtual void set_u_balance (int u_balance)
 Set u balance.
virtual int v_balance ()
 Get current v balance.
virtual void set_v_balance (int v_balance)
 Set v balance.
virtual unsigned int brightness ()
 Get current brightness.
virtual void set_brightness (unsigned int brightness)
 Set new brightness.
virtual unsigned int contrast ()
 Get current contrast.
virtual void set_contrast (unsigned int contrast)
 Set new contrast.
virtual unsigned int saturation ()
 Get current saturation.
virtual void set_saturation (unsigned int saturation)
 Set new saturation.
virtual int hue ()
 Get current hue.
virtual void set_hue (int hue)
 Set new hue.
virtual unsigned int exposure ()
 Get current exposure.
virtual void set_exposure (unsigned int exposure)
 Set new exposure.
virtual unsigned int gain ()
 Get current gain.
virtual void set_gain (unsigned int gain)
 Set new gain.
virtual const char * format ()
 Get the image format the camera currently uses.
virtual void set_format (const char *format)
 Set the image format the camera should use.
virtual unsigned int width ()
 Get the current width of the image.
virtual unsigned int height ()
 Get the current height of the image.
virtual void set_size (unsigned int width, unsigned int height)
 Set the image size the camera should use.
virtual bool horiz_mirror ()
 Return whether the camera image is horizontally mirrored.
virtual bool vert_mirror ()
 Return whether the camera image is vertically mirrored.
virtual void set_horiz_mirror (bool enabled)
 Set whether the camera should mirror images horizontally.
virtual void set_vert_mirror (bool enabled)
 Set whether the camera should mirror images vertically.
virtual unsigned int fps ()
 Get the number of frames per second that have been requested from the camera.
virtual void set_fps (unsigned int fps)
 Set the number of frames per second the camera tries to deliver.
virtual unsigned int lens_x_corr ()
 Get current lens x correction.
virtual unsigned int lens_y_corr ()
 Get current lens y correction.
virtual void set_lens_x_corr (unsigned int x_corr)
 Set lens x correction.
virtual void set_lens_y_corr (unsigned int y_corr)
 Set lens y correction.

Protected Member Functions

 V4L2Camera (const char *device_name, int dev)
 Protected Constructor.

Protected Attributes

char * _device_name
 Device name.

Friends

class V4LCamera

Detailed Description

Video4Linux 2 camera access implementation.

Todo:
UPTR method

Standards queries (VIDIOC_ENUMSTD)

v4l2_pix_format.field

Author:
Tobias Kellner

Definition at line 41 of file v4l2.h.


Constructor & Destructor Documentation

V4L2Camera::V4L2Camera ( const char *  device_name = "/dev/video0"  ) 

Constructor.

Parameters:
device_name device file name (e.g. /dev/video0)

Definition at line 71 of file v4l2.cpp.

References _device_name.

V4L2Camera::V4L2Camera ( const CameraArgumentParser cap  ) 

Constructor.

Initialize camera with parameters from camera argument parser. Supported arguments: *Required:

  • device=DEV, device file, for example /dev/video0 (required) *Optional:
  • read_method=METHOD, preferred read method READ: read() MMAP: memory mapping UPTR: user pointer
  • format=FOURCC, preferred format
  • size=WIDTHxHEIGHT, preferred image size
  • switch_u_v=true/false, switch U and V channels
  • fps=FPS, frames per second
  • aec=true/false, Auto Exposition enabled [warning: only valid on nao]
  • awb=true/false, Auto White Balance enabled
  • agc=true/false, Auto Gain enabled
  • h_flip=true/false, Horizontal mirror
  • v_flip=true/false, Vertical mirror
  • brightness=BRIGHT, Brightness [0-255] (def. 128)
  • contrast=CONTR, Contrast [0-127] (def. 64)
  • saturation=SAT, Saturation [0-256] (def. 128)
  • hue=HUE, Hue [-180-180] (def. 0)
  • red_balance=RB, Red Balance [0-255] (def. 128)
  • blue_balance=BB, Blue Balance [0-255] (def. 128)
  • exposure=EXP, Exposure [0-65535] (def. 60)
  • gain=GAIN, Gain [0-255] (def. 0)
  • lens_x=CORR, Lens Correction X [0-255] (def. 0)
  • lens_y=CORR, Lens Correction Y [0-255] (def. 0)
    Parameters:
    cap camera argument parser

Definition at line 121 of file v4l2.cpp.

References _device_name, CameraArgumentParser::get(), CameraArgumentParser::has(), and CameraControlImage::size().

V4L2Camera::~V4L2Camera (  )  [virtual]

Destructor.

Definition at line 403 of file v4l2.cpp.

References _device_name, close(), and stop().

V4L2Camera::V4L2Camera ( const char *  device_name,
int  dev 
) [protected]

Protected Constructor.

Gets called from V4LCamera, when the device has already been opened and determined to be a V4L2 device.

Parameters:
device_name device file name (e.g. /dev/video0)
dev file descriptor of the opened device

Definition at line 372 of file v4l2.cpp.

References _device_name, and close().


Member Function Documentation

bool V4L2Camera::auto_exposure (  )  [virtual]

Return whether auto exposure is enabled.

Returns:
true if auto exposure is enabled

Implements CameraControlColor.

Definition at line 1381 of file v4l2.cpp.

bool V4L2Camera::auto_gain (  )  [virtual]

Return whether auto gain is enabled.

Returns:
true if auto gain is enabled

Implements CameraControlColor.

Definition at line 1355 of file v4l2.cpp.

bool V4L2Camera::auto_white_balance (  )  [virtual]

Return whether auto white balance is enabled.

Returns:
true if auto white balance is enabled

Implements CameraControlColor.

Definition at line 1368 of file v4l2.cpp.

int V4L2Camera::blue_balance (  )  [virtual]

Get current blue balance.

Returns:
current blue balance value

Implements CameraControlColor.

Definition at line 1411 of file v4l2.cpp.

unsigned int V4L2Camera::brightness (  )  [virtual]

Get current brightness.

Returns:
current brightness value

Implements CameraControlColor.

Definition at line 1448 of file v4l2.cpp.

unsigned char * V4L2Camera::buffer (  )  [virtual]

Get access to current image buffer.

This will return a pointer to the current buffer. The buffer contains an image of the given colorspace, width and height.

Returns:
pointer to image buffer

Implements Camera.

Definition at line 1258 of file v4l2.cpp.

unsigned int V4L2Camera::buffer_size (  )  [virtual]

Size of buffer.

Gets the size in bytes of the buffer returned by buffer().

Returns:
size of buffer in bytes

Implements Camera.

Definition at line 1266 of file v4l2.cpp.

References CameraControlImage::size().

void V4L2Camera::capture (  )  [virtual]

Capture an image.

Although cameras shall operate with a continuous image flow where possible sometimes capturing an image means copying a buffer or advancing a buffer list pointer. This shall be done in this method. For a camera-using application it is mandatory to call capture() just before accessing the image buffer.

Implements Camera.

Definition at line 1191 of file v4l2.cpp.

References close(), fawkes::Time::set_time(), CameraControlImage::size(), and fawkes::Time::stamp().

fawkes::Time * V4L2Camera::capture_time (  )  [virtual]

Get the Time of the last successfully captured image.

Returns a Time representing the time when the last image was captured successfully. Note that calling this function is only valid after capture() and before dispose_buffer() has been called -- it is only valid when an image is currently available.

Returns:
Time of the currently processed image. The pointer shall be valid at least until the next call to dispose_buffer().
Exceptions:
NotImplementedException thrown if Camera does not support time stamping

Reimplemented from Camera.

Definition at line 1338 of file v4l2.cpp.

void V4L2Camera::close (  )  [virtual]

Close camera.

This closes the camera device. The camera must have been stopped before calling close().

Implements Camera.

Definition at line 1044 of file v4l2.cpp.

References CameraControlImage::size(), and stop().

Referenced by capture(), dispose_buffer(), open(), start(), stop(), V4L2Camera(), and ~V4L2Camera().

colorspace_t V4L2Camera::colorspace (  )  [virtual]

Colorspace of returned image.

Returns:
colorspace of image returned by buffer()

Implements Camera.

Definition at line 1327 of file v4l2.cpp.

unsigned int V4L2Camera::contrast (  )  [virtual]

Get current contrast.

Returns:
current contrast value

Implements CameraControlColor.

Definition at line 1461 of file v4l2.cpp.

void V4L2Camera::dispose_buffer (  )  [virtual]

Dispose current buffer.

Some cameras need disposal of the current buffer (for example to free space in a queue to retrieve the next image). This is done with this method. It has to be called after all work has been done on the image as desired. After dispose_buffer() has been called no further access may happen to the image buffer or undesired behavior may happen.

Implements Camera.

Definition at line 1274 of file v4l2.cpp.

References close().

unsigned int V4L2Camera::exposure (  )  [virtual]

Get current exposure.

Returns:
current exposure value

Implements CameraControlColor.

Definition at line 1500 of file v4l2.cpp.

void V4L2Camera::flush (  )  [virtual]

Flush image queue.

Some cameras may have an image buffer queue. With this it can happen that if the processing of an image took longer than desired it is needed to flush this buffer queue.

Implements Camera.

Definition at line 1184 of file v4l2.cpp.

const char * V4L2Camera::format (  )  [virtual]

Get the image format the camera currently uses.

Check implementation documentation for details on the format.

Returns:
a string describing the image format
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1527 of file v4l2.cpp.

unsigned int V4L2Camera::fps (  )  [virtual]

Get the number of frames per second that have been requested from the camera.

A return value of 0 means that fps haven't been set yet through the camera.

Returns:
the currently requested fps or 0 if not set yet

Reimplemented from CameraControlImage.

Definition at line 1592 of file v4l2.cpp.

unsigned int V4L2Camera::gain (  )  [virtual]

Get current gain.

Returns:
current gain value

Implements CameraControlColor.

Definition at line 1513 of file v4l2.cpp.

unsigned int V4L2Camera::height (  )  [virtual]

Get the current height of the image.

Returns:
height in pixels

Implements CameraControlImage.

Definition at line 1547 of file v4l2.cpp.

References pixel_height().

bool V4L2Camera::horiz_mirror (  )  [virtual]

Return whether the camera image is horizontally mirrored.

Returns:
true if the image is horizontally mirrored
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1562 of file v4l2.cpp.

int V4L2Camera::hue (  )  [virtual]

Get current hue.

Returns:
current hue value

Implements CameraControlColor.

Definition at line 1487 of file v4l2.cpp.

unsigned int V4L2Camera::lens_x_corr (  )  [virtual]

Get current lens x correction.

Returns:
current lens x correction
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1605 of file v4l2.cpp.

unsigned int V4L2Camera::lens_y_corr (  )  [virtual]

Get current lens y correction.

Returns:
current lens y correction
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1611 of file v4l2.cpp.

void V4L2Camera::open (  )  [virtual]

Open the camera.

The camera is opened, but image transfer not yet started. This can be used to detect general problems with the camera while delaying the real transfer startup until it is needed.

Implements Camera.

Definition at line 413 of file v4l2.cpp.

References _device_name, close(), and stop().

unsigned int V4L2Camera::pixel_height (  )  [virtual]

Height of image in pixels.

Returns:
height of image in pixels

Implements Camera.

Definition at line 1319 of file v4l2.cpp.

Referenced by height().

unsigned int V4L2Camera::pixel_width (  )  [virtual]

Width of image in pixels.

Returns:
width of image in pixels

Implements Camera.

Definition at line 1311 of file v4l2.cpp.

Referenced by width().

void V4L2Camera::print_info (  )  [virtual]

Print out camera information.

Shall print out camera information and current setup information on stdout.

Implements Camera.

Definition at line 1632 of file v4l2.cpp.

References _device_name.

bool V4L2Camera::ready (  )  [virtual]

Camera is ready for taking pictures.

The camera has been opened and started correctly and may now provide images.

Returns:
true, if the camera is ready, false otherwise

Implements Camera.

Definition at line 1176 of file v4l2.cpp.

int V4L2Camera::red_balance (  )  [virtual]

Get current red balance.

Returns:
current red balance value

Implements CameraControlColor.

Definition at line 1398 of file v4l2.cpp.

unsigned int V4L2Camera::saturation (  )  [virtual]

Get current saturation.

Returns:
current saturation value

Implements CameraControlColor.

Definition at line 1474 of file v4l2.cpp.

void V4L2Camera::set_auto_exposure ( bool  enabled  )  [virtual]

Enable/disable auto exposure.

Parameters:
enabled whether auto exposure should be enabled

Implements CameraControlColor.

Definition at line 1388 of file v4l2.cpp.

void V4L2Camera::set_auto_gain ( bool  enabled  )  [virtual]

Enable/disable auto gain.

Parameters:
enabled whether auto gain should be enabled

Implements CameraControlColor.

Definition at line 1361 of file v4l2.cpp.

void V4L2Camera::set_auto_white_balance ( bool  enabled  )  [virtual]

Enable/disable auto white balance.

Parameters:
enabled whether auto white balance should be enabled

Implements CameraControlColor.

Definition at line 1374 of file v4l2.cpp.

void V4L2Camera::set_blue_balance ( int  blue_balance  )  [virtual]

Set blue balance.

Parameters:
blue_balance new blue balance

Implements CameraControlColor.

Definition at line 1417 of file v4l2.cpp.

void V4L2Camera::set_brightness ( unsigned int  brightness  )  [virtual]

Set new brightness.

Parameters:
brightness new brightness

Implements CameraControlColor.

Definition at line 1454 of file v4l2.cpp.

void V4L2Camera::set_contrast ( unsigned int  contrast  )  [virtual]

Set new contrast.

Parameters:
contrast new contrast

Implements CameraControlColor.

Definition at line 1467 of file v4l2.cpp.

void V4L2Camera::set_exposure ( unsigned int  exposure  )  [virtual]

Set new exposure.

Parameters:
exposure new exposure

Implements CameraControlColor.

Definition at line 1506 of file v4l2.cpp.

void V4L2Camera::set_format ( const char *  format  )  [virtual]

Set the image format the camera should use.

Check implementation documentation for details on the format.

Parameters:
format the new image format
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1533 of file v4l2.cpp.

void V4L2Camera::set_fps ( unsigned int  fps  )  [virtual]

Set the number of frames per second the camera tries to deliver.

Parameters:
fps the new fps
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1598 of file v4l2.cpp.

References set_fps().

Referenced by set_fps().

void V4L2Camera::set_gain ( unsigned int  gain  )  [virtual]

Set new gain.

Parameters:
gain new gain

Implements CameraControlColor.

Definition at line 1519 of file v4l2.cpp.

void V4L2Camera::set_horiz_mirror ( bool  enabled  )  [virtual]

Set whether the camera should mirror images horizontally.

Parameters:
enabled if true, images should be mirrored horizontally
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1574 of file v4l2.cpp.

void V4L2Camera::set_hue ( int  hue  )  [virtual]

Set new hue.

Parameters:
hue new hue

Implements CameraControlColor.

Definition at line 1493 of file v4l2.cpp.

void V4L2Camera::set_image_number ( unsigned int  n  )  [virtual]

Set image number to retrieve.

If a camera is able to retrieve several images this method can be used to select the image to be retrieved with the next call to capture().

Parameters:
n image number to set

Implements Camera.

Definition at line 1344 of file v4l2.cpp.

void V4L2Camera::set_lens_x_corr ( unsigned int  x_corr  )  [virtual]

Set lens x correction.

Parameters:
x_corr new lens x correction
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1617 of file v4l2.cpp.

void V4L2Camera::set_lens_y_corr ( unsigned int  y_corr  )  [virtual]

Set lens y correction.

Parameters:
y_corr new lens y correction
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1624 of file v4l2.cpp.

void V4L2Camera::set_red_balance ( int  red_balance  )  [virtual]

Set red balance.

Parameters:
red_balance new red balance

Implements CameraControlColor.

Definition at line 1404 of file v4l2.cpp.

void V4L2Camera::set_saturation ( unsigned int  saturation  )  [virtual]

Set new saturation.

Parameters:
saturation new saturation

Implements CameraControlColor.

Definition at line 1480 of file v4l2.cpp.

void V4L2Camera::set_size ( unsigned int  width,
unsigned int  height 
) [virtual]

Set the image size the camera should use.

Parameters:
width new width of the image
height new height of the image
Exceptions:
Exception thrown for instance if size setting at run-time is not supported

Implements CameraControlImage.

Definition at line 1553 of file v4l2.cpp.

void V4L2Camera::set_u_balance ( int  u_balance  )  [virtual]

Set u balance.

Parameters:
u_balance new u balance

Implements CameraControlColor.

Definition at line 1430 of file v4l2.cpp.

void V4L2Camera::set_v_balance ( int  v_balance  )  [virtual]

Set v balance.

Parameters:
v_balance new v balance

Implements CameraControlColor.

Definition at line 1442 of file v4l2.cpp.

void V4L2Camera::set_vert_mirror ( bool  enabled  )  [virtual]

Set whether the camera should mirror images vertically.

Parameters:
enabled if true, images should be mirrored vertically
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1581 of file v4l2.cpp.

void V4L2Camera::start (  )  [virtual]

Start image transfer from the camera.

For many cameras opening the camera and starting transmission of images are two tasks. This method will simply initiate the transfer after the camera as been opened. And exception shall be thrown if the camera has not been opened.

Implements Camera.

Definition at line 1093 of file v4l2.cpp.

References close(), and stop().

void V4L2Camera::stop (  )  [virtual]

Stop image transfer from the camera.

This will stop the image transfer initiated with start(). This can be used to start and stop the image transfer at will without opening and closing operations inbetween.

Implements Camera.

Definition at line 1145 of file v4l2.cpp.

References close().

Referenced by close(), open(), start(), and ~V4L2Camera().

int V4L2Camera::u_balance (  )  [virtual]

Get current u balance.

Returns:
current u balance value

Implements CameraControlColor.

Definition at line 1424 of file v4l2.cpp.

int V4L2Camera::v_balance (  )  [virtual]

Get current v balance.

Returns:
current v balance value

Implements CameraControlColor.

Definition at line 1436 of file v4l2.cpp.

bool V4L2Camera::vert_mirror (  )  [virtual]

Return whether the camera image is vertically mirrored.

Returns:
true if the image is vertically mirrored
Exceptions:
NotImplementedException Not implemented by this control

Reimplemented from CameraControlImage.

Definition at line 1568 of file v4l2.cpp.

unsigned int V4L2Camera::width (  )  [virtual]

Get the current width of the image.

Returns:
width in pixels

Implements CameraControlImage.

Definition at line 1541 of file v4l2.cpp.

References pixel_width().


Member Data Documentation

char* V4L2Camera::_device_name [protected]

Device name.

Definition at line 133 of file v4l2.h.

Referenced by open(), print_info(), V4L2Camera(), and ~V4L2Camera().


The documentation for this class was generated from the following files: