QVMPlayerCamera Class Reference

Video source class for reading many video file formats, webcams and digital cameras. More...

#include <qvcameras/qvmplayercamera.h>

Inherits QVCamera.

List of all members.

Public Types

enum  OpenOption {
  Default = 0x0, RealTime = 0x1, Deinterlaced = 0x2, NoLoop = 0x4,
  RGBMEncoder = 0x8
}

Public Slots

bool grab ()
 Grabs a frame from camera input.
void pauseCam ()
void unpauseCam ()
void nextFrameCam ()
void setSpeedCam (double d)
 Set the camera speed.
void seekCam (QVCamera::TSeekType type, double pos)
 Moves the camera file to a given position.
void closeCam ()
bool link (QVWorker *, QString imageName)
bool link (QVWorker *, const QString imageY, const QString imageU, const QString imageV)

Public Member Functions

 QVMPlayerCamera (QString name=QString())
 ~QVMPlayerCamera ()
bool openCam (const QString &url, OpenOptions opts=Default)
 Opens a mplayer source given by its URL.
bool openCam (const QString &urlstring, unsigned int r, unsigned int c, OpenOptions opts=Default)
 Opens a mplayer source given by its URL, and scales output to a requested size.
bool openCam ()
 Opens a mplayer source using the internal properties assigned to it. (Overloaded function, provided by convenience; see QVPropertyContainer for details on properties). Used properties:
bool grab (QVImage< uChar, 3 > &image)
 Grabs a frame in RGB format.
bool grab (QVImage< uChar, 1 > &image)
 Grabs a gray scale frame.
bool grab (QVImage< uChar > &imgY, QVImage< uChar > &imgU, QVImage< uChar > &imgV)
 Grabs a frame in YUV format.
const QString getUrlBase () const
 Returns the current camera name (without path).
OpenOptions getOptions () const
 Returns current camera options.
int getBufferSize () const
 Returns the current frame buffer size.
unsigned int getFramesUpdated () const
 Returns the total number of updated frames.
unsigned int getRows () const
 Returns the number of rows of the buffer.
unsigned int getCols () const
 Returns the number of cols of the buffer.
double getFPS () const
 Returns the camera speed in frames per second.
double getTimeLength () const
 Returns the video file length in seconds.
double getTimePos () const
 Returns the current video position in seconds.
double getSpeed () const
 Returns the current video speed.
unsigned int getFramesGrabbed () const
 Returns number of frames grabbed.
unsigned int getFramesRead () const
 Returns number of frames read.
bool isLiveCamera () const
 Tells if the camera is a live camera.

Static Public Member Functions

static bool getFrame (const QString uri, QVImage< uChar, 3 > &img, int frame=0)
 Grabs a RGB image, from a camera specified with an URI.
static bool getFrame (const QString uri, QVImage< uChar, 1 > &img, int frame=0)
 Grabs a gray image, from a camera specified with an URI.
static bool getFrame (const QString uri, QVImage< uChar > &imgY, QVImage< uChar > &imgU, QVImage< uChar > &imgV, int frame=0)
 Grabs a YUV image, from a camera specified with an URI.


Detailed Description

Video source class for reading many video file formats, webcams and digital cameras.

This is an implementation of the class QVCamera, based on the program MPlayer. This program can read videos from a wide variety of media formats, webcams and digital cameras, and the class QVMPlayerCamera takes advantage of that feature. Thus the QVMPlayerCamera is a good, robust and versatile video input reader class.

Internally, when used to read from a video source compatible with MPlayer, the QVMPlayerCamera object will launch a copy of the MPlayer program, and redirect its output to a named pipe, from which will read the frames from the video source.

For a detailed usage of this class in a QVision application, see section QVision's basic programming model..

Video source identifier URL formats

Each video source is identified by a URL string, even for video files, webcams, remote videos, etc... this class opens a video source, and reads frames from it, until a stop condition arises or the video finishes.

Symplified camera URL format.

Format: just the path to a file or files. Type of formats

Todo:
Implement and document better this. Mind problems with unspecified camera parameters: fps, brightness, etc... Might be convenient for them to have default values setted in this kind of format.

Extended camera URL formats.

With previous format there can be incompleteness, ambiguous video input, and other problems. More specific URL formats follows: The format of this string depends of the type of the video source. Notation: [] means optional, {} means alternative:

Definition at line 230 of file qvmplayercamera.h.


Member Enumeration Documentation

enum QVMPlayerCamera::OpenOption

Open options for a mplayer camera. Combine them using OR (|).

Enumerator:
Default 
RealTime  Default camera (no realtime, do not discard frames, do not deinterlace, loop mode, produce YUV images).
Deinterlaced  Camera runs in an independent, real time thread.
NoLoop  Make mplayer deinterlace the image (odd lines).
RGBMEncoder  If video reaches end, do not loop. Instead, automatically close the camera.

Definition at line 243 of file qvmplayercamera.h.


Constructor & Destructor Documentation

QVMPlayerCamera::QVMPlayerCamera ( QString  name = QString()  ) 

Constructs a QVMPlayerCamera, which is initially in "Closed" status.

Definition at line 447 of file qvmplayercamera.cpp.

References QVPropertyContainer::inputFlag, and QVPropertyContainer::outputFlag.

QVMPlayerCamera::~QVMPlayerCamera (  ) 

Destroys a QVMPlayerCamera.

Definition at line 474 of file qvmplayercamera.cpp.

References closeCam().


Member Function Documentation

bool QVMPlayerCamera::openCam ( const QString &  url,
OpenOptions  opts = Default 
)

Opens a mplayer source given by its URL.

Parameters:
url URL of the mplayer source. See Video source identifier URL formats for URL formats.
opts Or'ed set of opening options (see QVMPlayerCamera::OpenOption).
Returns:
True if the camera was opened successfully, false otherwise.

Definition at line 608 of file qvmplayercamera.cpp.

References openCam().

Referenced by getFrame().

bool QVMPlayerCamera::openCam ( const QString &  urlstring,
unsigned int  r,
unsigned int  c,
OpenOptions  opts = Default 
)

Opens a mplayer source given by its URL, and scales output to a requested size.

(Overloaded function, provided by convenience).

Parameters:
url Camera identifying URL string. See Video source identifier URL formats for URL formats.
r Number of requested output rows.
c Number of requested output cols.
opts Camera opening options (see QVMPlayerCamera::openCam(const QString&,OpenOptions))
Returns:
True if the camera was opened successfully, false otherwise.

bool QVMPlayerCamera::openCam (  ) 

Opens a mplayer source using the internal properties assigned to it. (Overloaded function, provided by convenience; see QVPropertyContainer for details on properties). Used properties:

Returns:
True if the camera was opened successfully, false otherwise.

Definition at line 595 of file qvmplayercamera.cpp.

References Default, and RGBMEncoder.

Referenced by openCam().

bool QVMPlayerCamera::grab ( QVImage< uChar, 3 > &  image  ) 

Grabs a frame in RGB format.

If the camera is not opened with RGBMencoderMode option, this function will set param QVImage to null image.

Parameters:
image QVImage that will store grabbed frame.
Returns:
TRUE if success, FALSE if fail.

Definition at line 855 of file qvmplayercamera.cpp.

Referenced by getFrame().

bool QVMPlayerCamera::grab ( QVImage< uChar, 1 > &  image  ) 

Grabs a gray scale frame.

If the camera is opened with RGBMencoderMode option, this function will set param QVImage to null image.

Parameters:
image QVImage that will store grabbed frame.
Returns:
True if success, false otherwise.

Definition at line 872 of file qvmplayercamera.cpp.

bool QVMPlayerCamera::grab ( QVImage< uChar > &  imgY,
QVImage< uChar > &  imgU,
QVImage< uChar > &  imgV 
)

Grabs a frame in YUV format.

This function grabs the image in YUV format, storing each channel Y, U and V, in a separate QVImage of one channel. YUV format would be 422, thus QVImage corresponding to plane Y will be four times bigger than those corresponding to planes U and V.

If the camera is opened with RGBMencoderMode option, this function will set param QVImage's to null images.

Parameters:
imgY QVImage that will store grabbed frame Y channel.
imgU QVImage that will store grabbed frame U channel.
imgV QVImage that will store grabbed frame V channel.
Returns:
True if success, false otherwise.

Definition at line 831 of file qvmplayercamera.cpp.

const QString QVMPlayerCamera::getUrlBase (  )  const [inline]

Returns the current camera name (without path).

Returns:
Current camera name.
Deprecated:
Use getName() instead

Definition at line 313 of file qvmplayercamera.h.

OpenOptions QVMPlayerCamera::getOptions (  )  const [inline]

Returns current camera options.

Returns:
Current camera options.

Definition at line 317 of file qvmplayercamera.h.

int QVMPlayerCamera::getBufferSize (  )  const [inline]

Returns the current frame buffer size.

Returns:
Current frame buffer size.

Definition at line 321 of file qvmplayercamera.h.

unsigned int QVMPlayerCamera::getFramesUpdated (  )  const [inline]

Returns the total number of updated frames.

Returns:
Current total number of updated frames.

Definition at line 325 of file qvmplayercamera.h.

unsigned int QVMPlayerCamera::getRows (  )  const [inline]

Returns the number of rows of the buffer.

Returns:
Number of rows.

Definition at line 329 of file qvmplayercamera.h.

unsigned int QVMPlayerCamera::getCols (  )  const [inline]

Returns the number of cols of the buffer.

Returns:
Number of cols.

Definition at line 333 of file qvmplayercamera.h.

double QVMPlayerCamera::getFPS (  )  const [inline]

Returns the camera speed in frames per second.

Returns:
Camera speed in frames per second.

Definition at line 337 of file qvmplayercamera.h.

double QVMPlayerCamera::getTimeLength (  )  const [inline]

Returns the video file length in seconds.

Returns:
Video length in seconds.

Definition at line 341 of file qvmplayercamera.h.

double QVMPlayerCamera::getTimePos (  )  const [inline]

Returns the current video position in seconds.

Returns:
Current video position in seconds.

Definition at line 345 of file qvmplayercamera.h.

double QVMPlayerCamera::getSpeed (  )  const [inline]

Returns the current video speed.

Returns:
Current video speed (as a multiplier of the FPS).

Definition at line 349 of file qvmplayercamera.h.

unsigned int QVMPlayerCamera::getFramesGrabbed (  )  const [inline]

Returns number of frames grabbed.

Returns:
Number of successful frames returned by grab's

Definition at line 353 of file qvmplayercamera.h.

unsigned int QVMPlayerCamera::getFramesRead (  )  const [inline]

Returns number of frames read.

Returns:
Number of frames actually read by a camera.

Definition at line 357 of file qvmplayercamera.h.

bool QVMPlayerCamera::isLiveCamera (  )  const [inline]

Tells if the camera is a live camera.

Returns:
True if camera is a live camera.

Definition at line 361 of file qvmplayercamera.h.

static bool QVMPlayerCamera::getFrame ( const QString  uri,
QVImage< uChar, 3 > &  img,
int  frame = 0 
) [inline, static]

Grabs a RGB image, from a camera specified with an URI.

This function grabs a frame from a video file or url, in RGB format, without having to create explicitly a mplayer camera object, open it, skip frames to the desired, and close the camera.

Parameters:
uri Camera URL (see QVMPlayerCamera::openCam(const QString&,OpenOptions)).
image QVImage that will store grabbed frame.
frame frame number, 0 for first frame.
Returns:
TRUE if success, FALSE if fail.

Definition at line 371 of file qvmplayercamera.h.

References closeCam(), grab(), openCam(), and RGBMEncoder.

static bool QVMPlayerCamera::getFrame ( const QString  uri,
QVImage< uChar, 1 > &  img,
int  frame = 0 
) [inline, static]

Grabs a gray image, from a camera specified with an URI.

This function grabs a gray scale frame from a video file or url, without having to create explicitly a mplayer camera object, open it, skip frames to the desired, and close the camera.

Parameters:
uri Camera URL (see QVMPlayerCamera::openCam(const QString&,OpenOptions)).
image QVImage that will store grabbed frame.
frame frame number, 0 for first frame.
Returns:
TRUE if success, FALSE if fail.

Definition at line 391 of file qvmplayercamera.h.

References closeCam(), Default, grab(), and openCam().

static bool QVMPlayerCamera::getFrame ( const QString  uri,
QVImage< uChar > &  imgY,
QVImage< uChar > &  imgU,
QVImage< uChar > &  imgV,
int  frame = 0 
) [inline, static]

Grabs a YUV image, from a camera specified with an URI.

This function grabs a frame from a video file or url, in YUV format, without having to create explicitly a mplayer camera object, open it, skip frames to the desired, and close the camera.

Parameters:
uri Camera URL (see QVMPlayerCamera::openCam(const QString&,OpenOptions)).
imgY QVImage that will store grabbed frame Y channel.
imgU QVImage that will store grabbed frame U channel.
imgV QVImage that will store grabbed frame V channel.
frame frame number, 0 for first frame.
Returns:
TRUE if success, FALSE if fail.

Definition at line 416 of file qvmplayercamera.h.

References closeCam(), Default, grab(), and openCam().

bool QVMPlayerCamera::grab (  )  [slot]

Grabs a frame from camera input.

Grabs an image, and stores it in the corresponding properties of the camera: "RGB image", "Y channel image", "U channel image", and "V channel image".

Parameters:
image QVImage that will store grabbed frame.
Returns:
TRUE if success, FALSE if fail.

Definition at line 802 of file qvmplayercamera.cpp.

References QVPropertyContainer::writeOutputProperties().

Referenced by link().

void QVMPlayerCamera::pauseCam (  )  [slot]

Pauses the camera.

Definition at line 947 of file qvmplayercamera.cpp.

void QVMPlayerCamera::unpauseCam (  )  [slot]

Unpauses the camera.

Definition at line 955 of file qvmplayercamera.cpp.

void QVMPlayerCamera::nextFrameCam (  )  [slot]

Go to the next frame.

Definition at line 963 of file qvmplayercamera.cpp.

void QVMPlayerCamera::setSpeedCam ( double  d  )  [slot]

Set the camera speed.

Parameters:
d Camera speed (as a multiplier of the FPS)

Definition at line 971 of file qvmplayercamera.cpp.

void QVMPlayerCamera::seekCam ( QVCamera::TSeekType  type,
double  pos 
) [slot]

Moves the camera file to a given position.

Parameters:
type Type of seek: Current=0,Percentage=1,Absolute=2.
pos 
  • If in Current mode: Relative displacement with respect to the current position in seconds.
  • If in Percentage mode: Percentage of total video length.
  • If in Absolute mode: Absolute position in seconds.

void QVMPlayerCamera::closeCam (  )  [slot]

Closes the camera.

Definition at line 748 of file qvmplayercamera.cpp.

Referenced by getFrame(), and ~QVMPlayerCamera().


The documentation for this class was generated from the following files:
Generated on Thu Mar 13 19:18:17 2008 for QVision by  doxygen 1.5.3