upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Member Functions
VCAP Class Reference

API for the Video Capture driver. More...

Detailed Description

This UPM module captures a still frame from a Linux V4L device, such as a USB webcam, and and then allows you to save it as a JPEG image into a file.

The camera and driver in use must support streaming, mmap-able buffers and must provide data in YUYV format. This should encompass most video cameras out there. It has been tested with a few off the shelf cameras without any problems.

string defaultDev = "/dev/video0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
cout << "Using device " << defaultDev << endl;
cout << "Initializing..." << endl;
// Instantiate an VCAP instance, using the specified video device
upm::VCAP sensor(defaultDev);
// enable some debug/verbose output
sensor.setDebug(true);
// This is just a hint. The kernel can change this to a lower
// resolution that the hardware supports. Use getWidth() and
// getHeight() methods to see what the kernel actually chose if you
// care.
sensor.setResolution(1920, 1080);
// capture an image
sensor.captureImage();
// convert and save it as a jpeg
sensor.saveImage("video-img1.jpg");
cout << "Exiting..." << endl;

Public Member Functions

 VCAP (std::string videoDev=VCAP_DEFAULT_VIDEODEV)
 
 ~VCAP ()
 
bool setResolution (int width, int height)
 
bool captureImage ()
 
bool saveImage (std::string filename=VCAP_DEFAULT_OUTPUTFILE)
 
int getWidth () const
 
int getHeight () const
 
void setJPGQuality (unsigned int quality)
 
int getJPGQuality () const
 
void setDebug (bool enable)
 

Protected Member Functions

bool initVideoDevice ()
 
bool checkCapabilities ()
 
bool YUYV2JPEG (FILE *file)
 
bool allocBuffer ()
 
void releaseBuffer ()
 
bool doCaptureImage ()
 

Constructor & Destructor Documentation

VCAP ( std::string  videoDev = VCAP_DEFAULT_VIDEODEV)

VCAP object constructor

Parameters
videoDevThe path to the video device, default is /dev/video0.

Here is the call graph for this function:

~VCAP ( )

VCAP object destructor

Member Function Documentation

bool setResolution ( int  width,
int  height 
)

Set the desired resolution of the output image. Note, this is a hint to the underlying video driver. The video driver is free to lower the specified resolution if the hardware cannot support it. You can use getHeight() and getWidth() after calling this method to see what the video driver chose.

Parameters
widthThe desired width of the image.
widthThe desired height of the image.
Returns
true if the operation succeeded, false otherwise.

Here is the caller graph for this function:

bool captureImage ( )

Capture an image from the camera.

Returns
true if the operation succeeded, false otherwise.

Here is the call graph for this function:

bool saveImage ( std::string  filename = VCAP_DEFAULT_OUTPUTFILE)

Save the captured image (created with captureImage()) to a file in JPEG format. The file will be overwritten if it already exists.

Parameters
filenameThe name of the file in which to store the image.
Returns
true if the operation succeeded, false otherwise.
int getWidth ( ) const
inline

Return the current width of the image. You can use this method to determine if the video driver downgraded it after a call to setResolution().

Returns
true Current width of capture.
int getHeight ( ) const
inline

Return the current height of the image. You can use this method to determine if the video driver downgraded it after a call to setResolution().

Returns
true Current height of capture.

Here is the call graph for this function:

void setJPGQuality ( unsigned int  quality)

Set the JPEG quality.

Parameters
qualityA number between 0-100, with higher numbers meaning higher quality. Numbers less than 0 will be clamped to 0, numbers higher than 100 will be clamped to 100.

Here is the caller graph for this function:

int getJPGQuality ( ) const
inline

Get the current JPEG quality setting.

Returns
the current JPEG quality setting.
void setDebug ( bool  enable)
inline

Enable or disable debugging output.

Parameters
enabletrue to enable debugging, false otherwise

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