OpenCVWidget
 All Classes Files Functions Variables
Signals | Public Member Functions | Protected Slots | Protected Attributes | List of all members
OpenCVCapture Class Reference

Class to capture frames or single images using OpenCV. More...

#include <opencvcapture.h>

Signals

void frameCaptured (cv::Mat image)
 Emitted each time a new frame is captured.

Public Member Functions

 OpenCVCapture ()
 Constructor.
 ~OpenCVCapture ()
virtual void startCapture ()
 Start a capture.
void startCapture (QString source, int frameRate=-1)
 Start a capture while setting the source and frame rate.
void setSource (QString source)
 Set the video source.
QString getSource ()
 Return the capture source.
void setFrameRate (int rate)
 Set desired frame rate.
int getFrameRate ()
 Retrive the set frame rate.
void stopCapture ()
 Stop the capture.
void pauseCapture ()
 Pause the capture.
void resumeCapture ()
 Restart the capture.
void advanceCapture ()
 Manually read next frame in a stream.
void grab ()
 Manually grab next frame.
void loadImage (int loadFlag=1)
 Load a single image.
void loadImage (QString source, int loadFlag=1)
 Load a single image from the specified source.
cv::Mat getImage ()
 Return the current image.
double getCaptureProperty (int propId)
 Get a property.
bool setCaptureProperty (int propId, double value)
 Set a property.
bool isOpened ()
 Tell whether a video capture is opened.

Protected Slots

void captureFrame ()
 Captures a new frame when the timer asks it to.

Protected Attributes

QTimer * timer
 Timer used for setting capture frame rate.
cv::VideoCapture capture
 Capture object for video.
cv::Mat image
 Holds the most recently captured image.
QString captureSource
 Specifies the source identifier/file name.
int frameRate
 Holds the frame rate that controls the timer.

Detailed Description

Class to capture frames or single images using OpenCV.

This class integrates OpenCV and Qt. It is a class that handles both the capture of video and single images. It works well with OpenCVViewer, which can display OpenCV images.

Each time a new frame is captured, the signal frameCaptured() is emitted so the image can be accessed and processed or displayed elsewhere. A simple usage would be to connect OpenCVCapture's frameCaptured() signal with OpenCVViewer's setImage() slot to show new frames as soon as they are obtained.

Definition at line 24 of file opencvcapture.h.

Constructor & Destructor Documentation

OpenCVCapture::OpenCVCapture ( )

Constructor.

Creates a new OpenCVCapture. Be aware that the capture source must be set before any capture can commence. See setSource().

Definition at line 5 of file opencvcapture.cpp.

OpenCVCapture::~OpenCVCapture ( )

Definition at line 11 of file opencvcapture.cpp.

Member Function Documentation

void OpenCVCapture::advanceCapture ( )

Manually read next frame in a stream.

If no timer is set, this function can be used to manually read the next frame. This functions has no effect unless the frame rate is set to 0.

Definition at line 109 of file opencvcapture.cpp.

void OpenCVCapture::captureFrame ( )
protectedslot

Captures a new frame when the timer asks it to.

Definition at line 160 of file opencvcapture.cpp.

void OpenCVCapture::frameCaptured ( cv::Mat  image)
signal

Emitted each time a new frame is captured.

Definition at line 100 of file moc_opencvcapture.cpp.

double OpenCVCapture::getCaptureProperty ( int  propId)

Get a property.

Get any property from the capture device/file, as specified in http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get

Parameters
thedesired property.
Returns
the value of the requested property.

Definition at line 145 of file opencvcapture.cpp.

int OpenCVCapture::getFrameRate ( )

Retrive the set frame rate.

Note that this does not return the frame rate the camera or video source uses internally, only the frame rate this object will try to obtain pictures with.

Returns
the current frame rate of the capture timer. If frameRate is < 0 the program will attempt to determine the frame rate automatically from the input file.

Definition at line 82 of file opencvcapture.cpp.

Mat OpenCVCapture::getImage ( )

Return the current image.

This function returns the current image for further processing elsewhere. Note that this is a shallow copy (as per OpenCV's memory management).

Returns
a shallow copy of the moest recently capture image.

Definition at line 140 of file opencvcapture.cpp.

QString OpenCVCapture::getSource ( )

Return the capture source.

Returns
the string defining the current capture source.

Definition at line 69 of file opencvcapture.cpp.

void OpenCVCapture::grab ( )

Manually grab next frame.

Use to seek to a specific point in a video (when setProperty() cannot be used due to bug 1419 in OpenCV). Remember that this does not retrieve the frame, so be sure to call advanceCapture() after calling this. This function has no effect unless the frame rate is set to 0.

Definition at line 116 of file opencvcapture.cpp.

bool OpenCVCapture::isOpened ( )

Tell whether a video capture is opened.

Returns
true if a capture is opened (it may be paused), false if not.

Definition at line 155 of file opencvcapture.cpp.

void OpenCVCapture::loadImage ( int  loadFlag = 1)

Load a single image.

Instead of using OpenCV's VideoCapture to capture a stream of images, this method uses imread() to load a single image. The image stays in memory until overwritten by a new capture or a new image.

Parameters
loadFlagpassed directly through to OpenCV's imread().

Definition at line 123 of file opencvcapture.cpp.

void OpenCVCapture::loadImage ( QString  source,
int  loadFlag = 1 
)

Load a single image from the specified source.

Overloaded version of loadImage(). Allows you to pass the file name in and load it in a single step.

Parameters
sourcethe name of the file to load. This will be set as the capture source.
loadFlagpassed directly through to OpenCV's imread().

Definition at line 134 of file opencvcapture.cpp.

void OpenCVCapture::pauseCapture ( )

Pause the capture.

Pause the internal capture timer.

Definition at line 93 of file opencvcapture.cpp.

void OpenCVCapture::resumeCapture ( )

Restart the capture.

Resume the internal capture timer. For video input, this resumes where the video was paused, for live camera input, this resumes at the current frame.

Definition at line 98 of file opencvcapture.cpp.

bool OpenCVCapture::setCaptureProperty ( int  propId,
double  value 
)

Set a property.

Set any property from the capture device/file, as specified in http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set

Parameters
thedesired property.
thedesired value.
Returns
the result as returned by OpenCV.

Definition at line 150 of file opencvcapture.cpp.

void OpenCVCapture::setFrameRate ( int  rate)

Set desired frame rate.

Parameters
frameRatethe desired frame rate. If frameRate is < 0 the program will attempt to determine the frame rate automatically from the input file.

Definition at line 74 of file opencvcapture.cpp.

void OpenCVCapture::setSource ( QString  source)

Set the video source.

Usually a file name of the video you want to process. If only an integer is provided, the source is the connected camera with that number.

Definition at line 64 of file opencvcapture.cpp.

void OpenCVCapture::startCapture ( )
virtual

Start a capture.

When the capture source is set, use this method to begin capturing from a video source using OpenCV's VideoCapture. Whenever a new frame is captured, the signal frameCaptured() is emitted.

Definition at line 16 of file opencvcapture.cpp.

void OpenCVCapture::startCapture ( QString  source,
int  frameRate = -1 
)

Start a capture while setting the source and frame rate.

An overloaded version of startCapture() that allows you to set the source and frame rate while starting the capture.

Parameters
sourcethe source identifier (see setSource()).
frameRatethe desired frame rate. If frameRate is < 0 the program will attempt to determine the frame rate automatically from the input file. If frameRate is == 0, no timer will be started. Instead, use advanceCapture() to manually frab the frames.

Definition at line 57 of file opencvcapture.cpp.

void OpenCVCapture::stopCapture ( )

Stop the capture.

This stops the internal capture timer and releases the VideoCapture object. The current image will stay in memory until overwritten when a capture is started again.

Definition at line 87 of file opencvcapture.cpp.

Member Data Documentation

cv::VideoCapture OpenCVCapture::capture
protected

Capture object for video.

Definition at line 199 of file opencvcapture.h.

QString OpenCVCapture::captureSource
protected

Specifies the source identifier/file name.

Definition at line 201 of file opencvcapture.h.

int OpenCVCapture::frameRate
protected

Holds the frame rate that controls the timer.

Definition at line 202 of file opencvcapture.h.

cv::Mat OpenCVCapture::image
protected

Holds the most recently captured image.

Definition at line 200 of file opencvcapture.h.

QTimer* OpenCVCapture::timer
protected

Timer used for setting capture frame rate.

Definition at line 198 of file opencvcapture.h.


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