使用 Qt Creator 设置 OpenCV 2.4.2 [英] setting up OpenCV 2.4.2 with Qt Creator

查看:65
本文介绍了使用 Qt Creator 设置 OpenCV 2.4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了两种方法在 qt creator 中使用 opencv第一个使用 Mingw,其中 dll 和 .dll.a 文件已经通过 opencv 库下载,我只是在 .pro 文件中添加对 .dll.a 文件的引用,如下

I tried two methods to use opencv with qt creator first one using Mingw where the dlls and .dll.a files are already downloaded with the opencv library and I just add reference to the .dll.a files in the .pro file as follow

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:

I have a simple code to test 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();
}

但我遇到了如下构建问题

but I got a build issues as follow

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 个退出状态

C:\Users\Kato\Documents\QT projects\QtOpenCVYaRab\debug\main.o:-1: In function ~Mat': d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:278: error: undefined reference tocv::fastFree(void*)' d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()' :-1: error: collect2: ld returned 1 exit status

这里是一些编译输出:

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 文件夹中文件的引用,但我遇到了几乎相同的构建问题.

the second method is using cmake to compile the opencv library the using visual studio 2010 to build it and add references to the files in the bin folder but I got almost the same building issues.

推荐答案

#include "iostream"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main()
{
    IplImage *image = cvLoadImage("C:\\lena.jpg");
    Mat im(image);
    imshow("TEST",im);
    waitKey();
    return 0;
}

这是你的 main.cpp...上面的程序显示了 lena 的图片...使用双反斜杠来指示 Windows 平台上目录的更改...一些 imread 对我来说是如何工作的,所以我已经加载了图像为 IplImage 并将其转换为 Mat...u cn 也执行以下操作...

this is ur main.cpp...the above programme displays the picture of lena...use double backslashes for indicating change of directory on windows platform...some how the imread does work for me so i have loaded the image as IplImage and casted it to Mat...u cn do the following also..

 IplImage *image = cvLoadImage("C:\\lena.jpg",1);
 cvShowImage("TEST",image);
 cvWaitKey();

您的 .pro 文件应该包含前面提到的以下几行...

your .pro file should have the following lines as mentioned earlier...

INCLUDEPATH += D:\OpenCV\opencv\build\include

LIBS +=-LD:\OpenCV\opencv\build\x64\mingw\lib\
-lopencv_core242\
-lopencv_highgui242\
-lopencv_imgproc242\
-lopencv_video242\

并且您的系统变量名为 path 应该有

and your system variable named path should have

  1. D:\Opencv2.4.2\opencv\build\x86\vc9\bin(如果你有 Qt 4.8.1 for桌面 MSVC2008 (QtSDK) 调试作为您的目标)
  2. D:\Opencv2.4.2\opencv\build\x86\mingw\bin(如果您的目标基于 Qt MinGW x86)
  3. D:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc9(mingw)(我添加了这个因为它显示了一些奇怪的错误......你可以试试)

编辑路径变量后关闭 Qt ide/应用程序并重新启动它以反映系统变量更改..

after editing the path variable close the Qt ide/application and restart it for the system variable change to get reflected..

这篇关于使用 Qt Creator 设置 OpenCV 2.4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆