VAT  3.0
Video Analysis Tool
commonimage.h
1 #ifndef COMMONIMAGE_H
2 #define COMMONIMAGE_H
3 
4 #include <QImage>
5 #include <string>
6 #include <opencv2/core/core.hpp>
7 #include <opencv2/highgui/highgui.hpp>
8 
9 enum CVConversionType
10 {
11  TO_RGB,
12  TO_YUV
13 };
14 
21 class CommonImage : public QImage
22 {
23  //Q_OBJECT
24 public:
30  QImage(),
31  is_camera_beingused(false), is_file_beingused(false)
32  {}
33  CommonImage(const char * const xpm[]) :
34  QImage(xpm),
35  is_camera_beingused(false), is_file_beingused(false)
36  {}
37  CommonImage(const QImage &q) :
38  QImage(q),
39  is_camera_beingused(false), is_file_beingused(false)
40  {}
41  CommonImage(QImage* q) :
42  QImage(*q),
43  is_camera_beingused(false), is_file_beingused(false)
44  {}
45  CommonImage(const QSize &size, Format format) :
46  QImage(size, format),
47  is_camera_beingused(false), is_file_beingused(false)
48  {}
49  CommonImage(const uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
50  QImage(data, width, height, format, cleanupFunction, cleanupInfo),
51  is_camera_beingused(false), is_file_beingused(false)
52  {}
53  CommonImage(const uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
54  QImage(data, width, height, bytesPerLine, format, cleanupFunction, cleanupInfo),
55  is_camera_beingused(false), is_file_beingused(false)
56  {}
57  CommonImage(int width, int height, Format format) :
58  QImage(width, height, format),
59  is_camera_beingused(false), is_file_beingused(false)
60  {}
61  CommonImage(uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
62  QImage(data, width, height, format, cleanupFunction, cleanupInfo),
63  is_camera_beingused(false), is_file_beingused(false)
64  {}
65  CommonImage(uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
66  QImage(data, width, height, bytesPerLine, format, cleanupFunction, cleanupInfo),
67  is_camera_beingused(false), is_file_beingused(false)
68  {}
69  CommonImage(cv::Mat& source);
70  CommonImage(const QString &fileName, const char *format);
71  CommonImage(int devNumber);
72 
73  ~CommonImage();
74 
75  using QImage::operator =;
76 
77  // Warning. These functions allocate new data.
78  static QImage formatconv_CV2QT(const cv::Mat& input);
79  static cv::Mat formatconv_QT2CV(const QImage input);
80  static cv::Mat formatconv_QT2CV_YUV(const QImage input);
81 
82  cv::Mat toCVMat();
83  void toCVMat(cv::Mat& output);
84  cv::Mat toCVYUVMat();
85 
86  void applyCVMask(const cv::Mat& mask);
87 
88  bool captureFromCamera(int device);
89  bool captureFromVideoFile(std::string fn);
90  double getCaptureAttribute(int propid);
91  int getCaptureFPS();
93  bool captureSkipToTime(double secs);
94 
95  bool grabCap();
96  void closeCap();
97 
98  void convertFromMat(const cv::Mat& input);
99 
100  CommonImage& operator = (const cv::Mat input);
101 
102 protected:
103  void cleanseCommonImageData();
104  void cleanseQImageData(int w = 0, int h = 0, Format fmt = QImage::Format_Invalid);
105 
106 private:
107  cv::Mat cvimg;
108  cv::VideoCapture vcapturer;
109 
110  std::string capt_filename;
111 
112  bool is_camera_beingused;
113  bool is_file_beingused;
114  bool is_mat_beingedited;
115 
116 signals:
117 
118 public slots:
119 
120 };
121 
122 #endif // COMMONIMAGE_H
CommonImage()
CommonImage Derived from all the QImage constructors.
Definition: commonimage.h:29
CommonImage & operator=(const cv::Mat input)
CommonImage::operator = A much more comfortable alias for convertFromMat.
Definition: commonimage.cpp:343
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.
Definition: commonimage.cpp:238
static QImage formatconv_CV2QT(const cv::Mat &input)
CommonImage::formatconv_CV2QT Copies a CV Mat data to a new QImage.
Definition: commonimage.cpp:63
cv::Mat toCVYUVMat()
CommonImage::toCVYUVMat Copies and transforms this image data to a cv::Mat with a YUV (YCrCb) colorsp...
Definition: commonimage.cpp:201
void closeCap()
CommonImage::closeCap If a camera or video file is being used, it is closed.
Definition: commonimage.cpp:271
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...
Definition: commonimage.cpp:313
bool captureFromCamera(int device)
CommonImage::captureFromCamera Opens the camera to grab images with grabCap(). If a file or a camera ...
Definition: commonimage.cpp:216
static cv::Mat formatconv_QT2CV(const QImage input)
CommonImage::formatconv_QT2CV Copies a QImage data into a new OpenCV Mat.
Definition: commonimage.cpp:94
void applyCVMask(const cv::Mat &mask)
CommonImage::applyCVMask Applies a binary mask to this image.
Definition: commonimage.cpp:173
cv::Mat toCVMat()
CommonImage::toCVMat Copies this image data to a new allocated cv::Mat, which is returned.
Definition: commonimage.cpp:160
The CommonImage class This is a class made to solve the headache you&#39;ll probably get when working bot...
Definition: commonimage.h:21
int getCaptureFPS()
CommonImage::getCaptureFPS Shows how many Frames Per Seconds does the captured media play...
Definition: commonimage.cpp:366
int getCaptureFrameInterval()
CommonImage::getCaptureFrameInterval Shows the interval in milliseconds between two consecutive frame...
Definition: commonimage.cpp:380
void convertFromMat(const cv::Mat &input)
CommonImage::convertFromMat Copies the data from a cv::Mat. [I&#39;ve got my doubts on whether this funct...
Definition: commonimage.cpp:283
~CommonImage()
CommonImage::~CommonImage Takes a broom and <s>takes everything it finds below a carpet</s> cleans ev...
Definition: commonimage.cpp:407
bool captureSkipToTime(double secs)
CommonImage::captureSkipToTime If capturing from a video file, this allows to skip to a video time...
Definition: commonimage.cpp:394
double getCaptureAttribute(int propid)
CommonImage::getCaptureAttribute Retrieves some attribute from the Video Capturer.
Definition: commonimage.cpp:355
Definition: BackgroundRecLigth.h:20