OpenCVWidget
|
00001 #ifndef OPENCVWIDGET_H 00002 #define OPENCVWIDGET_H 00003 00004 #include <QtGui> 00005 #include <QGLWidget> 00006 #include <opencv2/highgui/highgui.hpp> 00007 #include <opencv2/core/core.hpp> 00008 #include <math.h> 00009 00010 // On Windows, GL_BGR is not defined by default. Fix that: 00011 #ifndef GL_BGR 00012 #define GL_BGR 0x80E0 00013 #endif 00014 00015 class QGLShaderProgram; 00016 00031 class OpenCVWidget : public QGLWidget 00032 { 00033 Q_OBJECT 00034 00035 public: 00042 OpenCVWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0); 00043 ~OpenCVWidget(); 00044 00050 QSize sizeHint() const; 00051 00059 void startCapture(); 00060 00071 void startCapture(QString source, int frameRate = -1, bool autoDisplay = true); 00072 00079 void setSource(QString source); 00080 00086 QString getSource(); 00087 00093 void setFrameRate(int rate); 00094 00104 int getFrameRate(); 00105 00112 void stopCapture(); 00113 00119 void pauseCapture(); 00120 00127 void resumeCapture(); 00128 00135 void advanceCapture(); 00136 00145 void grab(); 00146 00154 void loadImage(int loadFlag = 1); 00155 00165 void loadImage(QString source, bool autoDisplay = true, int loadFlag = 1); 00166 00177 cv::Mat getImage(); 00178 00187 void enableAutoDisplay(bool value); 00188 00196 bool getAutoDisplay(); 00197 00205 void updateDisplay(); 00206 00217 double getCaptureProperty(int propId); 00218 00230 bool setCaptureProperty(int propId, double value); 00231 00237 bool isOpened(); 00238 00245 cv::Point mapPoint(cv::Point widgetCoords); 00246 00247 protected: 00248 void initializeGL(); 00249 void paintGL(); 00250 void resizeGL(int width, int height); 00251 void mousePressEvent(QMouseEvent *event); 00252 void mouseMoveEvent(QMouseEvent* event); 00253 00254 protected: 00255 GLuint texture; 00256 QVector<QVector2D> vertices; 00257 QVector<QVector2D> texCoords; 00258 QTimer *timer; 00259 cv::VideoCapture capture; 00260 cv::Mat image; 00261 cv::Mat displayImage; 00262 int frameRate; 00263 QString captureSource; 00264 bool autoDisplay; 00265 00266 protected slots: 00267 void captureFrame(); 00268 00269 signals: 00270 void frameCaptured(); 00271 void mouseClicked(QMouseEvent* event); 00272 void mouseMoved(QMouseEvent* event); 00273 00274 }; 00275 00276 #endif