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. |
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.
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.
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.
|
protectedslot |
Captures a new frame when the timer asks it to.
Definition at line 160 of file opencvcapture.cpp.
|
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
the | desired 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.
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).
Definition at line 140 of file opencvcapture.cpp.
QString OpenCVCapture::getSource | ( | ) |
Return the 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.
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.
loadFlag | passed 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.
source | the name of the file to load. This will be set as the capture source. |
loadFlag | passed 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
the | desired property. |
the | desired value. |
Definition at line 150 of file opencvcapture.cpp.
void OpenCVCapture::setFrameRate | ( | int | rate | ) |
Set desired frame rate.
frameRate | the 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.
|
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.
source | the source identifier (see setSource()). |
frameRate | the 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.
|
protected |
Capture object for video.
Definition at line 199 of file opencvcapture.h.
|
protected |
Specifies the source identifier/file name.
Definition at line 201 of file opencvcapture.h.
|
protected |
Holds the frame rate that controls the timer.
Definition at line 202 of file opencvcapture.h.
|
protected |
Holds the most recently captured image.
Definition at line 200 of file opencvcapture.h.
|
protected |
Timer used for setting capture frame rate.
Definition at line 198 of file opencvcapture.h.