我尝试了两种方法使用qt creator和opencv。第一种方法是使用Mingw,此时opencv库已经下载好了dlls和.dll.a文件,我只需要在.pro文件中添加对.dll.a文件的引用,具体操作如下:
INCLUDEPATH += D:\\OpenCV\\opencv\\build\\include
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_calib3d242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_contrib242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_core242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_features2d242.dll.a
我有一个简单的代码来测试opencv:
#include <QtCore/QCoreApplication>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat image;
return a.exec();
}
但我遇到了以下构建问题
C:\Users\Kato\Documents\QT projects\QtOpenCVYaRab\debug\main.o:-1: 在函数
~Mat'中:
d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:278: 错误:对cv::fastFree(void*)的引用未定义
d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:367: 错误:对cv::Mat::deallocate()的引用未定义
:-1: 错误:collect2: ld 返回 1 退出状态
以下是一些编译输出:
Running build steps for project QtOpenCVYaRab...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/Kato/Documents/QT projects/QtOpenCVYaRab'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
debug/main.o:d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtOpenCVYaRab.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project QtOpenCVYaRab (target: Desktop)
When executing build step 'Make'
第二种方法是使用CMake编译OpenCV库,然后使用Visual Studio 2010进行构建,并将引用添加到bin文件夹中的文件中,但我遇到了几乎相同的构建问题。