标签:
1. 编译安装OpenCV2.4.9 本博已有文章描述
2. 安装Qt和QtCreator
从qt-project.org 下载Qt安装文件
qt-opensource-linux-x64-5.4.1.run
从Windows下下载拷贝过来的,*.run没有执行权限,
chmod a+x qt-opensource-linux-x64-5.4.1.run
双击就安装完了Qt 和 QtCreator
3. 配置Qt
gedit /home/jackielee/Qt5.4.1/5.4/gcc_64/mkspecs/linux-g++-64/qmake.conf
增加两行
QMAKE_INCDIR = /usr/include/opencv
QMAKE_LIBS = -lcvaux -lcv -lcxcore -lhighgui -lml
4. 测试代码
#include <cv.h> #include <highgui.h> int main(int argc, char *argv[]) { //QCoreApplication a(argc, argv); IplImage *img = 0; img = cvLoadImage("3.png",-1); cvNamedWindow("lena", 1); cvShowImage("lena", img); cvWaitKey(0); return 0; }
另外需要注意一点的是,需要将opencv的头文件和库文件与Qt关联起来,所以在双击QtCreator工程下到***.pro文件,在其后面添加下列代码:
INCLUDEPATH += /usr/local/include /usr/local/include/opencv /usr/local/include/opencv2 LIBS += /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_imgproc.so
即此时对应的整个***.pro文件内容如下:
#------------------------------------------------- # # Project created by QtCreator 2012-07-09T22:01:34 # #------------------------------------------------- QT += core QT -= gui TARGET = test1 CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += /usr/local/include /usr/local/include/opencv /usr/local/include/opencv2 LIBS += /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_imgproc.so
5. 构建 运行 运行成功
参考
http://blog.csdn.net/crzy_sparrow/article/details/7315366
http://www.cnblogs.com/tornadomeet/archive/2012/07/10/2584702.html
http://www.cnblogs.com/wuyuegb2312/archive/2012/12/10/2811591.html
标签:
原文地址:http://www.cnblogs.com/okgogo2000/p/4306994.html