camera_usb
Public Member Functions | Static Public Attributes | List of all members
camera::CamUsb Class Reference

#include <cam_usb.h>

Inheritance diagram for camera::CamUsb:

Public Member Functions

 CamUsb (std::string const &device)
 
 ~CamUsb ()
 
void fastInit (int width, int height)
 
virtual int listCameras (std::vector< CamInfo > &cam_infos) const
 
virtual bool open (const CamInfo &cam, const AccessMode mode=Master)
 
bool isOpen () const
 
virtual const CamInfo * getCameraInfo () const
 
virtual bool close ()
 
virtual bool grab (const GrabMode mode=SingleFrame, const int buffer_len=1)
 
virtual bool retrieveFrame (base::samples::frame::Frame &frame, const int timeout=1000)
 
bool storeFrame (base::samples::frame::Frame &frame, std::string const &file_name)
 
virtual bool isFrameAvailable ()
 
virtual int skipFrames ()
 
virtual bool setIpSettings (const CamInfo &cam, const IPSettings &ip_settings) const
 
virtual bool setAttrib (const int_attrib::CamAttrib attrib, const int value)
 
virtual bool setAttrib (const double_attrib::CamAttrib attrib, const double value)
 
virtual bool setAttrib (const str_attrib::CamAttrib attrib, const std::string value)
 
virtual bool setAttrib (const enum_attrib::CamAttrib attrib)
 
virtual bool isAttribAvail (const int_attrib::CamAttrib attrib)
 
virtual bool isAttribAvail (const double_attrib::CamAttrib attrib)
 
virtual bool isAttribAvail (const str_attrib::CamAttrib attrib)
 
virtual bool isAttribAvail (const enum_attrib::CamAttrib attrib)
 
virtual int getAttrib (const int_attrib::CamAttrib attrib)
 
virtual double getAttrib (const double_attrib::CamAttrib attrib)
 
virtual std::string getAttrib (const str_attrib::CamAttrib attrib)
 
virtual bool isAttribSet (const enum_attrib::CamAttrib attrib)
 
bool isV4L2AttribAvail (const int control_id, std::string name="")
 
int getV4L2Attrib (const int control_id)
 
bool setV4L2Attrib (const int control_id, const int value)
 
bool setFrameSettings (const base::samples::frame::frame_size_t size, const base::samples::frame::frame_mode_t mode, const uint8_t color_depth, const bool resize_frames=true)
 
virtual bool getFrameSettings (base::samples::frame::frame_size_t &size, base::samples::frame::frame_mode_t &mode, uint8_t &color_depth)
 
virtual bool triggerFrame ()
 
virtual bool setToDefault ()
 
bool printCameraInformations ()
 
virtual bool setCallbackFcn (void(*pcallback_function)(const void *p), void *p)
 
virtual void synchronizeWithSystemTime (uint32_t time_interval)
 
virtual void saveConfiguration (uint8_t index)
 
virtual void loadConfiguration (uint8_t index)
 
virtual void getRange (const double_attrib::CamAttrib attrib, double &dmin, double &dmax)
 
virtual void getRange (const int_attrib::CamAttrib attrib, int &imin, int &imax)
 
virtual int getFileDescriptor () const
 
enum CAM_USB_MODE getCamMode ()
 
double calculateFPS ()
 

Static Public Attributes

static const uint32_t CAM_ID = 0
 

Detailed Description

Allows configuration and image-requesting of cameras supported by Video4Linux.

  1. Pass the video-device (e.g. '/dev/video0') to the constructor.
  2. Call 'listCameras()' to get the CamInfo structure of the single supported camera.
  3. Opens the camera with 'open()' entering the configuration mode via v4l2.
  4. Call setFrameSettings() to define the image size.
  5. (optional) Use 'setAttrib()' to change default attributes of the camera interface and 'setV4L2Attrib()' to change special private attributes of the camera not defined by the interface.
  6. Call 'grab()' to create and start the image requesting. If the camera mode camera::MultiFrame or camera::Continuously is used GStreamer is used for the image requesting. In mode::SingleFrame v4l2 is directly used to request the camera images which should be stressfull for the usb bus. To stop the image requesting and enter the configuration mode again mode::Stop has been passed.
  7. Use 'retrieveFrame()' to get a Frame.

You can use 'fastInit(width, height)' for the steps 2, 3 and 4.

Constructor & Destructor Documentation

camera::CamUsb::CamUsb ( std::string const &  device)
camera::CamUsb::~CamUsb ( )

Member Function Documentation

double camera::CamUsb::calculateFPS ( )
inline
bool camera::CamUsb::close ( )
virtual

Close camera, sets camera mode to CAM_USB_NONE (configuration or image requesting is not possible anymore).

Returns
Always true.
void camera::CamUsb::fastInit ( int  width,
int  height 
)

Fast configuration of the camera (step 2 to 4). Opens the camera and sets the frame size. After this configuration, additional attributes can be set, the camera can be started by using grab() and the images can be retrieved with retrieveFrame(). If the camera does not support the passed width and height, an appropriate image size will be set.

int camera::CamUsb::getAttrib ( const int_attrib::CamAttrib  attrib)
virtual

Returns the control value or throws a std::runtime_error.

double camera::CamUsb::getAttrib ( const double_attrib::CamAttrib  attrib)
virtual

Returns the fps of the camera or throws a std::runtime_error.

virtual std::string camera::CamUsb::getAttrib ( const str_attrib::CamAttrib  attrib)
inlinevirtual
const CamInfo * camera::CamUsb::getCameraInfo ( ) const
virtual
Returns
NULL if camera is not open.
enum CAM_USB_MODE camera::CamUsb::getCamMode ( )
inline
int camera::CamUsb::getFileDescriptor ( ) const
virtual

The pipeline must be running.

Returns
-1 if an error occurred.
bool camera::CamUsb::getFrameSettings ( base::samples::frame::frame_size_t &  size,
base::samples::frame::frame_mode_t &  mode,
uint8_t &  color_depth 
)
virtual
virtual void camera::CamUsb::getRange ( const double_attrib::CamAttrib  attrib,
double &  dmin,
double &  dmax 
)
inlinevirtual
void camera::CamUsb::getRange ( const int_attrib::CamAttrib  attrib,
int &  imin,
int &  imax 
)
virtual
int camera::CamUsb::getV4L2Attrib ( const int  control_id)

Allows to request the last read control value (the value will not be re-read from the camera).

Exceptions
std::runtime_error
Parameters
control_idControl id to request.
Returns
false if the camera is not in configuration mode or the passed id is unknown.
bool camera::CamUsb::grab ( const GrabMode  mode = SingleFrame,
const int  buffer_len = 1 
)
virtual

To start the pipeline, just set 'mode' to sth. other than Stop (SingleFrame, MultiFrame or Continuously). Images are always grapped continuously. Pass Stop to stop grabbing and reenter the configuration mode. Could throw std::runtime_error if the passed mode is unknown or the mode should changed during the pipeline is running.

Returns
Return false if the pipeline could not be started.
bool camera::CamUsb::isAttribAvail ( const int_attrib::CamAttrib  attrib)
virtual

Returns true if the attribute can be used with the camera. Excludes int_attrib::ExposureValue at the moment, because problems occurs using the Microsoft LiveCam.

bool camera::CamUsb::isAttribAvail ( const double_attrib::CamAttrib  attrib)
virtual

Returns true if the fps could be set on the camera.

virtual bool camera::CamUsb::isAttribAvail ( const str_attrib::CamAttrib  attrib)
inlinevirtual
bool camera::CamUsb::isAttribAvail ( const enum_attrib::CamAttrib  attrib)
virtual

Returns true if the attribute can be used with the camera.

bool camera::CamUsb::isAttribSet ( const enum_attrib::CamAttrib  attrib)
virtual

Returns true if the enumeration attribute is set or throws a std::runtime_error.

bool camera::CamUsb::isFrameAvailable ( )
virtual

Same as grab(), returns true if a new image is available.

bool camera::CamUsb::isOpen ( ) const
bool camera::CamUsb::isV4L2AttribAvail ( const int  control_id,
std::string  name = "" 
)

Can be used to check the availability of v4l2 control IDs directly.

Parameters
control_idid of the control to check.
nameFor different cameras the same private base control id addresses different controls. If the name parameter is used, the name of the control is checked as well.
Returns
false if the camera is not in configuration mode or the attribute is not available.
int camera::CamUsb::listCameras ( std::vector< CamInfo > &  cam_infos) const
virtual

Adds the single cam_info structure to the passed vector. The cam_info.display_name will be added later, as soon as the connection to the camera has been opened.

virtual void camera::CamUsb::loadConfiguration ( uint8_t  index)
inlinevirtual
bool camera::CamUsb::open ( const CamInfo &  cam,
const AccessMode  mode = Master 
)
virtual

Stores the passed CamInfo structure and opens camera for configuration via v4l2.

Returns
Always true.
bool camera::CamUsb::printCameraInformations ( )

List all camera informations. BASE_LOG_LEVEL has to be set to INFO.

bool camera::CamUsb::retrieveFrame ( base::samples::frame::Frame &  frame,
const int  timeout = 1000 
)
virtual

Reads a JPEG and initializes the passed frame (blocking read).

Returns
true if a new image could be requested in 'timeout' msecs.
virtual void camera::CamUsb::saveConfiguration ( uint8_t  index)
inlinevirtual
bool camera::CamUsb::setAttrib ( const int_attrib::CamAttrib  attrib,
const int  value 
)
virtual

Write the control value to the camera or throws a std::runtime_error.

bool camera::CamUsb::setAttrib ( const double_attrib::CamAttrib  attrib,
const double  value 
)
virtual

Sets the FPS or throws a std::runtime_error. This method just sets the member variable mFps. You have to close and reopen the camera to take the new fps will take into account.

virtual bool camera::CamUsb::setAttrib ( const str_attrib::CamAttrib  attrib,
const std::string  value 
)
inlinevirtual
bool camera::CamUsb::setAttrib ( const enum_attrib::CamAttrib  attrib)
virtual

Switches the enumeration attribute or throws a std::runtime_error.

virtual bool camera::CamUsb::setCallbackFcn ( void(*)(const void *p)  pcallback_function,
void *  p 
)
inlinevirtual
bool camera::CamUsb::setFrameSettings ( const base::samples::frame::frame_size_t  size,
const base::samples::frame::frame_mode_t  mode,
const uint8_t  color_depth,
const bool  resize_frames = true 
)

If necessary 'size' will be changed to a valid one. 'mode' should be set to base::samples::frame::MODE_JPEG and 'color_depth' to the bytes per pixel.

bool camera::CamUsb::setIpSettings ( const CamInfo &  cam,
const IPSettings &  ip_settings 
) const
virtual
bool camera::CamUsb::setToDefault ( )
virtual

Sets all control values on the camera back to default values. The image size and the fps are not affected. The connection to the camera has to be closed.

bool camera::CamUsb::setV4L2Attrib ( const int  control_id,
const int  value 
)

Sets the v4l2 control id directly.

Parameters
control_idControl id to set the value for.
valueValue to set.
Exceptions
std::runtime_errorif the configuration mode is not active, the passed id is unknown or writeControlValue() throws an exception.
Returns
true if the value could be set.
int camera::CamUsb::skipFrames ( )
virtual

Skips the current image if available.

Returns
true if an image has been skipped.
bool camera::CamUsb::storeFrame ( base::samples::frame::Frame &  frame,
std::string const &  file_name 
)

Stores the last retrieved frame to 'file_name'.

virtual void camera::CamUsb::synchronizeWithSystemTime ( uint32_t  time_interval)
inlinevirtual
bool camera::CamUsb::triggerFrame ( )
virtual

Frames are requested continuously.

Member Data Documentation

const uint32_t camera::CamUsb::CAM_ID = 0
static

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