VAT  3.0
Video Analysis Tool
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
CommonImage Class Reference

The CommonImage class This is a class made to solve the headache you'll probably get when working both in Qt and OpenCV. It's a QImage child class, so it's designed to work most of the time in Qt (to show the image in a QPixmap every frame, for example). As a bonus, it also has some methods to directly capture frames from a camera or a video file. More...

#include <commonimage.h>

Inheritance diagram for CommonImage:

Public Member Functions

 CommonImage ()
 CommonImage Derived from all the QImage constructors.
 
 CommonImage (const char *const xpm[])
 
 CommonImage (const QImage &q)
 
 CommonImage (QImage *q)
 
 CommonImage (const QSize &size, Format format)
 
 CommonImage (const uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)
 
 CommonImage (const uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)
 
 CommonImage (int width, int height, Format format)
 
 CommonImage (uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)
 
 CommonImage (uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)
 
 CommonImage (cv::Mat &source)
 CommonImage::CommonImage Creates a CommonImage copying data from a cv::Mat. More...
 
 CommonImage (const QString &fileName, const char *format)
 CommonImage This constructor is reimplemented. If it fails to open a file using the QImage constructor (file is not an image), it tries to open it as a video. More...
 
 CommonImage (int devNumber)
 CommonImage::CommonImage Tries to open the camera specified by devNumber. More...
 
 ~CommonImage ()
 CommonImage::~CommonImage Takes a broom and <s>takes everything it finds below a carpet</s> cleans everything.
 
cv::Mat toCVMat ()
 CommonImage::toCVMat Copies this image data to a new allocated cv::Mat, which is returned. More...
 
void toCVMat (cv::Mat &output)
 
cv::Mat toCVYUVMat ()
 CommonImage::toCVYUVMat Copies and transforms this image data to a cv::Mat with a YUV (YCrCb) colorspace. More...
 
void applyCVMask (const cv::Mat &mask)
 CommonImage::applyCVMask Applies a binary mask to this image. More...
 
bool captureFromCamera (int device)
 CommonImage::captureFromCamera Opens the camera to grab images with grabCap(). If a file or a camera is currently being used, it is released. More...
 
bool captureFromVideoFile (std::string fn)
 CommonImage::captureFromVideoFile Opens a video file to grab images with grabCap(). If a file or a camera is currently being used, it is released. More...
 
double getCaptureAttribute (int propid)
 CommonImage::getCaptureAttribute Retrieves some attribute from the Video Capturer. More...
 
int getCaptureFPS ()
 CommonImage::getCaptureFPS Shows how many Frames Per Seconds does the captured media play. More...
 
int getCaptureFrameInterval ()
 CommonImage::getCaptureFrameInterval Shows the interval in milliseconds between two consecutive frames in the captured media play. More...
 
bool captureSkipToTime (double secs)
 CommonImage::captureSkipToTime If capturing from a video file, this allows to skip to a video time. More...
 
bool grabCap ()
 
void closeCap ()
 CommonImage::closeCap If a camera or video file is being used, it is closed.
 
void convertFromMat (const cv::Mat &input)
 CommonImage::convertFromMat Copies the data from a cv::Mat. [I've got my doubts on whether this function has memory leaks or not. If it does, the main suspect is the rgbSwapped function at the end.]. More...
 
CommonImageoperator= (const cv::Mat input)
 CommonImage::operator = A much more comfortable alias for convertFromMat. More...
 

Static Public Member Functions

static QImage formatconv_CV2QT (const cv::Mat &input)
 CommonImage::formatconv_CV2QT Copies a CV Mat data to a new QImage. More...
 
static cv::Mat formatconv_QT2CV (const QImage input)
 CommonImage::formatconv_QT2CV Copies a QImage data into a new OpenCV Mat. More...
 
static cv::Mat formatconv_QT2CV_YUV (const QImage input)
 

Protected Member Functions

void cleanseCommonImageData ()
 
void cleanseQImageData (int w=0, int h=0, Format fmt=QImage::Format_Invalid)
 CommonImage::cleanseQImageData This function is intended to resize and clean all the QImage data. [I'm pretty sure it has some SERIOUS memory leaks that I can't track (Is this->data reallocated or not?). Valgrind is a b*tch to use with Qt.]. More...
 

Detailed Description

The CommonImage class This is a class made to solve the headache you'll probably get when working both in Qt and OpenCV. It's a QImage child class, so it's designed to work most of the time in Qt (to show the image in a QPixmap every frame, for example). As a bonus, it also has some methods to directly capture frames from a camera or a video file.

Constructor & Destructor Documentation

CommonImage::CommonImage ( cv::Mat &  source)

CommonImage::CommonImage Creates a CommonImage copying data from a cv::Mat.

Parameters
sourceA cv::Mat image.
CommonImage::CommonImage ( const QString &  fileName,
const char *  format 
)

CommonImage This constructor is reimplemented. If it fails to open a file using the QImage constructor (file is not an image), it tries to open it as a video.

Parameters
fileNameImage or video path.
formatUsed only in image case. Ignored if opening a video.
CommonImage::CommonImage ( int  devNumber)

CommonImage::CommonImage Tries to open the camera specified by devNumber.

Parameters
devNumberNumber of the camera to open. Use 0 to open the default camera.

Member Function Documentation

void CommonImage::applyCVMask ( const cv::Mat &  mask)

CommonImage::applyCVMask Applies a binary mask to this image.

Parameters
mask
bool CommonImage::captureFromCamera ( int  device = 0)

CommonImage::captureFromCamera Opens the camera to grab images with grabCap(). If a file or a camera is currently being used, it is released.

Parameters
deviceCamera device index. Default is 0, which is the default camera.
Returns
True if the camera is successfully opened. False if not.
bool CommonImage::captureFromVideoFile ( std::string  fn)

CommonImage::captureFromVideoFile Opens a video file to grab images with grabCap(). If a file or a camera is currently being used, it is released.

Parameters
fnVideo file name.
Returns
True if the video file is successfully opened. False if not.
bool CommonImage::captureSkipToTime ( double  secs)

CommonImage::captureSkipToTime If capturing from a video file, this allows to skip to a video time.

Parameters
secs
Returns
void CommonImage::cleanseQImageData ( int  w = 0,
int  h = 0,
Format  fmt = QImage::Format_Invalid 
)
protected

CommonImage::cleanseQImageData This function is intended to resize and clean all the QImage data. [I'm pretty sure it has some SERIOUS memory leaks that I can't track (Is this->data reallocated or not?). Valgrind is a b*tch to use with Qt.].

Parameters
wNew image width. Default is 0, which absolutely empties this image.
hNew image height. Default is 0, which absolutely empties this image.
fmtNew image format. Default is QImage::Format_Invalid, a dummy to indicate that you want to keep the format intact.
void CommonImage::convertFromMat ( const cv::Mat &  input)

CommonImage::convertFromMat Copies the data from a cv::Mat. [I've got my doubts on whether this function has memory leaks or not. If it does, the main suspect is the rgbSwapped function at the end.].

Parameters
input
QImage CommonImage::formatconv_CV2QT ( const cv::Mat &  input)
static

CommonImage::formatconv_CV2QT Copies a CV Mat data to a new QImage.

Parameters
inputCV Mat to be converted.
Returns
A QImage with the same data and format.
cv::Mat CommonImage::formatconv_QT2CV ( const QImage  input)
static

CommonImage::formatconv_QT2CV Copies a QImage data into a new OpenCV Mat.

Parameters
inputA QImage.
Returns
An OpenCV Mat with the same data and format.
double CommonImage::getCaptureAttribute ( int  propid)

CommonImage::getCaptureAttribute Retrieves some attribute from the Video Capturer.

Parameters
propidA requested attribute code (See VideoCapture::get method in OpenCV for more details)
Returns
int CommonImage::getCaptureFPS ( )

CommonImage::getCaptureFPS Shows how many Frames Per Seconds does the captured media play.

Returns
A positive, greater-than-zero amount indicating the FPS if a media is being captured. -1 if no media is being captured.
int CommonImage::getCaptureFrameInterval ( )

CommonImage::getCaptureFrameInterval Shows the interval in milliseconds between two consecutive frames in the captured media play.

Returns
A positive, greater-than-zero amount indicating the interval if a media is being captured. -1 if no media is being captured.
CommonImage & CommonImage::operator= ( const cv::Mat  input)

CommonImage::operator = A much more comfortable alias for convertFromMat.

Parameters
input
Returns
cv::Mat CommonImage::toCVMat ( )

CommonImage::toCVMat Copies this image data to a new allocated cv::Mat, which is returned.

Returns
cv::Mat CommonImage::toCVYUVMat ( )

CommonImage::toCVYUVMat Copies and transforms this image data to a cv::Mat with a YUV (YCrCb) colorspace.

Returns

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