在Qt中搭建OpenCV的运行环境
为了在Qt环境中搭建OpenCV,本人安装了如下软件
-
OpenCV2.3.1
-
Qt 4.6.2
-
QtCreator 2.8.1
在操作系统配置系统环境变量
Path = C:\Qt4.6.2\bin; C:\Qt4.6.2\include; D:\OpenCV23\build\x86\vc9\bin;
在QtCreator创建Qt控制台程序,工程名为OpenCV
编辑OpenCV.pro
-
QT += core
-
-
QT -= gui
-
-
TARGET = OpenCV
-
CONFIG += console
-
CONFIG -= app_bundle
-
-
TEMPLATE = app
-
-
SOURCES += main.cpp
-
-
# Add OpenCV include directory
-
INCLUDEPATH += D:\OpenCV23\build\include\
-
# Add OpenCV library direcotry and library files
-
LIBS += -LD:\OpenCV23\lib\build\x86\vc9\lib\
-
-lopencv_core231d \
-
-lopencv_imgproc231d \
-
-lopencv_highgui231d \
-
-lopencv_legacy231d
编辑main.cpp文件
-
#include <QCoreApplication>
-
-
#include <opencv/cv.h> // Load opencv Library
-
#include <opencv2/core/core.hpp>
-
#include <opencv2/highgui/highgui.hpp>
-
-
using namespace cv; // Load cv namespace
-
int main(int argc, char *argv[])
-
{
-
QCoreApplication a(argc, argv);
-
Mat image = imread("lena.jpg"); // Load image
-
namedWindow("OpenCV"); // Name window
-
imshow("OpenCV",image); // Show image
-
waitKey(0); // Keep image show alway
-
return a.exec();
-
}
把需要显示的图片放到指定的Debug或Release文件夹,编译运行
如果编译通过,但运行时不能正常显示图片,如以下结果,请确认已经将图片放入正确路径。
其他详细细节,请参看相关资料,如:http://blog.csdn.net/qiurisuixiang/article/details/8665278
阅读(1962) | 评论(0) | 转发(0) |