CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Public Member Functions | Static Public Member Functions | List of all members
cavapa_gui::Camera Class Reference

The class for a camera source. More...

#include <camera.h>

Inheritance diagram for cavapa_gui::Camera:
cavapa_gui::Source

Public Member Functions

 Camera (SourceID desired_id=UNDEFINED_SOURCE)
 Creates a new source. More...
 
 DISALLOW_COPY_AND_ASSIGN (Camera)
 Copy and assign of the class is not allowed.
 
bool canRecord () const override
 Returns information on the source recording abilities. More...
 
FrameCapture get (FrameTime passed_time) override
 Retrieves the next frame from the camera. More...
 
double getBarrelCorrection () override
 Returns the barrel correction applied to the source frames. More...
 
std::string getDescription () const override
 Retrieves the description of the source. More...
 
int getDeviceID () const
 Retrieves the device number used to initialize the device. More...
 
double getFramerate () const override
 Retrieves the framerate. More...
 
FrameTime getPosition () const overridefinal
 Retrieves the current time position of the source. More...
 
std::vector< std::string > getRecordings () const
 Returns the names of the video files that were recorded. More...
 
cv::Size getResolution () const override
 Retrieves the resolution of the source. More...
 
SourceType getSourceType () const override
 Returns the type of the source. More...
 
SourceStats getStats () override
 Retrieves the source statistical information. More...
 
bool hasNew () override
 Checks whether the device has a new image to be retrieved or not. More...
 
bool open (int index)
 Opens a new camera object. More...
 
bool open (const std::string &url)
 Opens a new camera object. More...
 
bool isOpen () const override
 Checks if the source has been initialized. More...
 
bool isPlaying () const override
 Checks whether the source is playing or not. More...
 
bool record (const std::string &filename, const std::string &codec="") override
 Starts the recording of the source to the file. More...
 
void setBarrelCorrection (double amount) override
 Sets the new barrel correction value. More...
 
bool setResolution (const cv::Size &new_size) override
 Sets the source resolution. More...
 
void stop () override
 Stops the camera from recording. More...
 
- Public Member Functions inherited from cavapa_gui::Source
 DISALLOW_COPY_AND_ASSIGN (Source)
 Copy and assign of the class is not allowed.
 
virtual SourceID getID () const final
 Gets the unique source ID number. More...
 
virtual void play ()
 Starts to play the source. More...
 
virtual void resetStats () final
 Resets the source statistics.
 

Static Public Member Functions

static std::string getCodec ()
 Retrieves the current codec used. More...
 
static double getDefaultFPS ()
 Retrieves the default framerate that has been set. More...
 
static bool setCodec (const std::string &codec)
 Sets recorders codec for new videos. More...
 
static void setDefaultFPS (double fps)
 Sets the cameras default framerate. More...
 

Additional Inherited Members

- Protected Member Functions inherited from cavapa_gui::Source
 Source (SourceID desired_id=UNDEFINED_SOURCE)
 General Source creator. More...
 
- Protected Attributes inherited from cavapa_gui::Source
SourceStats statistics = EMPTY_SOURCE_STATS
 The statistics of the source.
 

Detailed Description

The class for a camera source.

The class is used to retrieve frames from HW cameras and network streams. The class provides a Recorder that can save frames to disk into video file.

HW camera frame retrievals take about 2ms. Recording the frame to a file at the same time takes about 3ms per camera. However, if the FPS retrieval is too high for that particular camera, it starts lag and can take up to 30-90 ms per image retrieval. This is solved in the OpenCVCapture by multithreading the retrieval process.

By multithreading the retrieval process, the programs base application can be sure that it get's either a new image from the camera or a duplicate of the last image it already showed. Showing the last image twice in a row is not a problem at all, because that's exactly what happens when you cut your frame rate in half, you just see the same image a little bit longer.

Author
Petri Partanen

Constructor & Destructor Documentation

cavapa_gui::Camera::Camera ( SourceID  desired_id = UNDEFINED_SOURCE)
inline

Creates a new source.

Parameters
desired_idThe desired ID number. Use UNDEFINED_SOURCE if you do not want to define it to a specific ID. This does not check if the source with the given ID already exists. The ID number will not be given to another new sources with UNDEFINED_SOURCE ID number.

Member Function Documentation

bool cavapa_gui::Camera::canRecord ( ) const
inlineoverridevirtual

Returns information on the source recording abilities.

Returns
True if the source can record, false otherwise.

Implements cavapa_gui::Source.

FrameCapture cavapa_gui::Camera::get ( FrameTime  passed_time)
overridevirtual

Retrieves the next frame from the camera.

The time supplied to the function informs the source about how much time has passed since the last image retrieval. The source will depend on its internal clock, either retrieving a new image or returning the buffered image that it retrieved previously.

Parameters
passed_timeThe time passed since the last call (in milliseconds).
Returns
The latest frame capture. This will actually return a reference to the original image, so you are NOT allowed to edit it! Otherwise the source buffer will be altered too. This is just the way OpenCV handles Mat memory.
Remarks
Forcing a camera to not skip frames will produce lag. Also, please note that stereo cameras are not (yet) supported. The first capture index (0) is retrieved from the OpenCV capturing device. Several buffers will need to be implemented for multichannel support.

TODO: Handle error flag!

Implements cavapa_gui::Source.

double cavapa_gui::Camera::getBarrelCorrection ( )
inlineoverridevirtual

Returns the barrel correction applied to the source frames.

Returns
The barrel effect value.

Implements cavapa_gui::Source.

static std::string cavapa_gui::Camera::getCodec ( )
inlinestatic

Retrieves the current codec used.

Returns
The codec name.
Remarks
The same codec is used for all recordings. Individual cameras cannot have unique codecs.
static double cavapa_gui::Camera::getDefaultFPS ( )
inlinestatic

Retrieves the default framerate that has been set.

The framerate used for the cameras do not give any information on their current framerate capabilities.

Returns
The default framerate.
std::string cavapa_gui::Camera::getDescription ( ) const
inlineoverridevirtual

Retrieves the description of the source.

Returns
The source description.
Remarks
You cannot trust it 100%. OpenCV does not provide any API to recognize camera hardware. See: https://code.ros.org/trac/opencv/ticket/935 Qt is used get the camera description. It is however unclear if the string returned by QCamera does match with the actual device used by OpenCV.

Implements cavapa_gui::Source.

int cavapa_gui::Camera::getDeviceID ( ) const
inline

Retrieves the device number used to initialize the device.

Returns
Device ID-number or UNKNOWN_DEVICE if not available.
double cavapa_gui::Camera::getFramerate ( ) const
overridevirtual

Retrieves the framerate.

Returns
The framerate or 0.0 if not supported.

Implements cavapa_gui::Source.

FrameTime cavapa_gui::Camera::getPosition ( ) const
inlinefinaloverridevirtual

Retrieves the current time position of the source.

Returns
The source time position.
0. Cameras do not support this method.

Implements cavapa_gui::Source.

std::vector< string > cavapa_gui::Camera::getRecordings ( ) const

Returns the names of the video files that were recorded.

Returns
The list of recorded files.
cv::Size cavapa_gui::Camera::getResolution ( ) const
inlineoverridevirtual

Retrieves the resolution of the source.

Returns
The source resolution.

Implements cavapa_gui::Source.

SourceType cavapa_gui::Camera::getSourceType ( ) const
overridevirtual

Returns the type of the source.

Returns
The source type.

Reimplemented from cavapa_gui::Source.

SourceStats cavapa_gui::Camera::getStats ( )
overridevirtual

Retrieves the source statistical information.

Returns
The source statistics.

Implements cavapa_gui::Source.

bool cavapa_gui::Camera::hasNew ( )
inlineoverridevirtual

Checks whether the device has a new image to be retrieved or not.

This checks if the FrameTime on the buffered image differs from what was retrieved on the last get().

Returns
True if a new image available or false otherwise.
True. Cameras always report new images despite of what is in the buffer.

Implements cavapa_gui::Source.

bool cavapa_gui::Camera::isOpen ( ) const
inlineoverridevirtual

Checks if the source has been initialized.

Returns
True if initialized, false otherwise.

Implements cavapa_gui::Source.

bool cavapa_gui::Camera::isPlaying ( ) const
inlineoverridevirtual

Checks whether the source is playing or not.

Returns
True if the source is playing or false otherwise.
True. Cameras are always playing.

Implements cavapa_gui::Source.

bool cavapa_gui::Camera::open ( int  index)

Opens a new camera object.

Parameters
indexThe device index number.
Returns
True if opened succesfully or false otherwise.
bool cavapa_gui::Camera::open ( const std::string &  url)

Opens a new camera object.

Parameters
urlThe device url.
Returns
True if opened succesfully or false otherwise.
bool cavapa_gui::Camera::record ( const std::string &  filename,
const std::string &  codec = "" 
)
overridevirtual

Starts the recording of the source to the file.

This can also be used to start an entirely new video file during the recording. The recording file will change immediately.

Parameters
filenameThe path of the recording file.
codecThe codec to be used for recording.
Returns
True if the recording started or false otherwise.

Implements cavapa_gui::Source.

void cavapa_gui::Camera::setBarrelCorrection ( double  amount)
overridevirtual

Sets the new barrel correction value.

The value is used to correct barrel effect (lens correction) on each image that the source will return.

Parameters
amountThe barrel value.

Implements cavapa_gui::Source.

bool cavapa_gui::Camera::setCodec ( const std::string &  codec)
static

Sets recorders codec for new videos.

See the list of codecs at http://www.fourcc.org/codecs.php

Parameters
codecThe new Codec.
Returns
True if the new codec was set or false otherwise.
Remarks
The same codec is used globally for all camera recordings. You cannot set individual codecs.
static void cavapa_gui::Camera::setDefaultFPS ( double  fps)
inlinestatic

Sets the cameras default framerate.

This is applied to the cameras that do not give out any other framerate values. This will affect most USB cameras for example.

Parameters
fpsThe new framerate to be set.
bool cavapa_gui::Camera::setResolution ( const cv::Size &  new_size)
overridevirtual

Sets the source resolution.

Parameters
new_sizeThe new resolution for the source.
Returns
True if the resolution was set, false otherwise.

Implements cavapa_gui::Source.

void cavapa_gui::Camera::stop ( )
overridevirtual

Stops the camera from recording.

This stops the recorder and let's it write the rest of the buffer to the file.

Implements cavapa_gui::Source.


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