1、在新文件夾testqt下創建源代碼文件main.cpplinux
#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> using namespace cv; int main() { Mat image; image=imread("test.jpg"); imshow("meinv",image); waitKey(); return 0; }
2、在源代碼文件目錄下執行qmakeapp
3、修改testqt.pro以下ui
###################################################################### # Automatically generated by qmake (2.01a) ?? 12? 22 16:35:37 2015 ###################################################################### TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += $OPENCV_HOME/include LIBS += -lGLU -lGL -lglut `pkg-config --libs opencv` # Input SOURCES += main.cpp
4、編譯運行spa
$ qmakecode
$ makeip
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -IPENCV_HOME/include -I. -o main.o main.cppqt
g++ -m64 -Wl,-O1 -o testqt main.o -L/usr/lib/x86_64-linux-gnu -lGLU -lGL -lglut `pkg-config --libs opencv` -lQtGui -lQtCore -lpthread it
將test.jpg拷入pip
$ lsio
main.cpp main.o Makefile test.jpg testqt testqt.pro
$ ./testqt