在QtCreator中将OpenCV 2.3与Qt一起使用 [英] Using OpenCV 2.3 with Qt in QtCreator
问题描述
由于OpenCV 2.3的发行版终于发布了,所以我想编译并安装此最新发行版到我的系统上.当我经常使用Qt和QtCreator时,我当然希望能够在我的Qt项目中使用它.我已经尝试了几种方法几个小时,但总是会出错:
as the release of OpenCV 2.3 is finally out, I wanted to compile and install this latest release on my system. As I often work with Qt and the QtCreator I of course wanted to be able to use it in my Qt projects. I've tried several methods now for some hours but always get errors:
首次尝试:使用WITH_QT编译OpenCV 2.3
首先,我想这样做,就像我对2.2发行版所做的一样.为此,我遵循了本指南: http://knowtheabc .wordpress.com/2011/02/25/windows-opencv-and-qt-creator/
First I wanted to do it just like I did with the 2.2 release which worked fine for me. For this I followed this guide: http://knowtheabc.wordpress.com/2011/02/25/windows-opencv-and-qt-creator/
- 下载了源代码
- 设置CMake,并告诉它创建MInGW Makefile,并在我的C:\ Qt ...路径中指定
g++.exe
,gcc.exe
和qmake.exe
的路径,检查WITH_QT并生成用于发布的Makefile. - 使用
mingw32-make
和mingw32-make install
构建并将其安装在外壳中
- Downloaded the source code
- Set up CMake and told it to create MInGW Makefiles and specified the paths to the
g++.exe
,gcc.exe
andqmake.exe
in my C:\Qt... paths, checked WITH_QT and generated Makefiles for a release. - Built and installed it in a shell using
mingw32-make
andmingw32-make install
成功完成此操作后,我只需要将路径添加到我的".pro"文件中,就可以构建一些使用OpenCV的漂亮软件了(回到我使用2.2版本时).基本上,最后一部分描述如下: http://knowtheabc.wordpress. com/2011/02/25/opencv-in-qt/
After this was completed successfully, I just needed to add the paths to my ".pro" file and was able to build some nice software that uses OpenCV (back at the time where I used the 2.2 release). Basically the last part is described here: http://knowtheabc.wordpress.com/2011/02/25/opencv-in-qt/
因此,我尝试对2.3版本进行相同的操作,该版本已成功编译,与旧版本一样.它甚至可以构建我的示例程序,但是一旦执行它,它就会再次关闭并返回:-1073741515
So I tried the same with the 2.3 release which compiled successfully just as with the old release. It even builds my example program but as soon as I execute it, it closes again and returns: -1073741515
第二种尝试:使用MinGW使用预构建的OpenCV超级包
由于第一种方法不起作用,因此我尝试使用预构建版本.尽管这些都没有启用WITH_QT,但我仍然想尝试.
As the first method didn't work I tried to use the pre-build versions. Though these don't have the WITH_QT enabled, I still wanted to try.
因此,我下载了超级包装,将其提取并放在了某个地方.然后,我想像以前一样做,然后将路径包括到include文件夹和dll添加到我的".pro"文件中:
So I downloaded the superpack, extracted and put it somewhere. I then wanted to do the same as I did before and added the paths to the include folder and the dlls to my ".pro" file:
INCLUDEPATH+= C:/workspace/opencv/OpenCV2.3/build/include
LIBS+= C:/workspace/opencv/OpenCV2.3/build/x64/mingw/bin/*.dll
作为编译器,我使用了当前Qt SDK随附的MinGW编译器.但这在构建时崩溃:
As compiler I used the MinGW compiler that comes with the current Qt SDK. But this crashes while building:
C:/workspace/opencv/OpenCV2.3/build/x64/mingw/bin/libopencv_calib3d230.dll: file not recognized: File format not recognized
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\CoinDetector.exe] Error 1
mingw32-make: *** [release] Error 2
第三次尝试:与第二次一样,但是使用了VC2008编译器
我也尝试使用Qt SDK随附的vc2008编译器进行相同的操作.因此,我选择了编译器,并修改了".pro"文件中的路径以供使用:
I tried the same thing with the vc2008 compiler that comes with the Qt SDK as well. So I selected the compiler and adapted the path in the ".pro" file to use:
LIBS+= C:/workspace/opencv/OpenCV2.3/build/x64/vc9/bin/*.dll
但这也会因无法读取dll的错误而崩溃:
But this also crashes with an error that it can't read the dll:
C:/workspace/opencv/OpenCV2.3/build/x64/vc9/bin/opencv_calib3d230.dll : fatal error LNK1107: Ungültige oder beschädigte Datei: Lesen bei 0x2F0 nicht möglich.
这是我的设置:
So here my settings:
- Win7 Professional x64
- 已安装最新的Qt SDK(4.7.3)
- OpenCV 2.3版本
有人知道这里可能有什么问题吗?希望获得帮助!
Does anybody have an idea what might be wrong here? Would be glad for any help!
推荐答案
我刚将QT 4.7.3与OpenCV2.3配合使用.不幸的是,我必须安装Microsoft的VC ++ 2008 Express Edition和CDB调试器(均为Microsoft的免费产品). 好消息是我现在可以在IDE,VS 2008和Qt Creator中为Opencv开发.
I just got my QT 4.7.3 to work with OpenCV2.3. Unfortunately I had to install VC++2008 Express Edition and the CDB Debugger from Microsoft (both are freebies from Microsoft). The good part is that I can now develop for Opencv in both IDE, VS 2008, and Qt Creator.
这些是我的.pro文件的设置:
These are the settings of my .pro file:
INCLUDEPATH += C:/OpenCV2.3/build/include
INCLUDEPATH += C:/OpenCV2.3/build/include/opencv
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_calib3d230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_contrib230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_core230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_features2d230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_flann230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_highgui230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_imgproc230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_objdetect230.lib
LIBS += C:/OpenCV2.3/build/x86/vc9/lib/opencv_video230.lib
请记住,在项目设置"中选择MSVC编译器
Remember, select the MSVC compiler in your Projects Settings
我尝试过不知道有多少种不同的方法可以使其与MinGW一起使用,但到目前为止,尚不正确. 我也使用Windows 7 64位...但是我正在开发32位,我想如果我使用x64库,可能会得到64位项目.
I have tried I don't know how many different approaches to make it work with MinGW, but not the right one so far. I'm also in Windows 7 64 bits...but I am developing for 32 bits, I suppose that if I use the x64 libraries I might get 64 bit projects to work.
祝你好运
安德烈斯
这篇关于在QtCreator中将OpenCV 2.3与Qt一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!