1. Select: File -> New -> Project -> Search "QT" -> Qt GUI Application, enter the name of the project, the next step ... be new.
Select the dependent modules: the most basic QtCore, QtGui, QtWidgets some audio / video, network, database, XML, OpenGl related modules, you can check directly to use.
Select QtGuiApplication2.ui -> Open With -> Qt Designer -> OK
Pull a OPenGL control onto a form
Change control to select the name for the upgrade to mat-> Right ...
Enhance the class name: MatView -> Click Add -> upgrade -> ctrl + F to save interface, as shown below
Header Files right -> type guide -> Add Class -> class life: MatView -> complete -> to confirm, as shown below
MatView.h Code
Once #pragma // importing the library #include <QOpenGLWidget> // inherited QOpenGLWidget class MatView: public QOpenGLWidget { the Q_OBJECT public: // Constructor MatView (the QWidget * P); ~ MatView (); // overload a function void the paintEvent (QPaintEvent * E); };
MatView.cpp Code
#include "QtGuiApplication2.h" #include <QtWidgets/QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QtGuiApplication2 w; w.show(); return a.exec(); }
main.cpp Code
#include "MatView.h" #include <opencv2 / core.hpp> #include <opencv2 / imgproc.hpp> #include <opencv2 / imgcodecs.hpp> #include <the QImage> #include <QPainter> the using namespace CV; // override a function, as long as he will call window changes, the business logic can not handle this function, the image processing only void MatView the paintEvent :: (QPaintEvent * E) { Mat imread the src = ( "E: \\ \\ VS2015Opencv vs2015 \ \ Project \\ \\ 12.jpg Picture "); QImage img (src.data, src.cols, src.rows, QImage :: Format_RGB888); QPainter Painter; painter.begin (the this); painter.drawImage (QPoint ( 0, 0), IMG); } // constructor is called the parent class, as well as the parent process in which, so to call it MatView :: MatView (the QWidget * P): QOpenGLWidget (P) { } MatView ::~MatView(){ }