在 QtCreator 中将 OpenCV 2.3 与 Qt 结合使用

发布于 2024-11-24 18:21:03 字数 2303 浏览 2 评论 0原文

随着 OpenCV 2.3 版本终于发布,我想在我的系统上编译并安装这个最新版本。由于我经常使用 Qt 和 QtCreator,我当然希望能够在我的 Qt 项目中使用它。我现在已经尝试了几种方法几个小时,但总是遇到错误:

第一次尝试:使用WITH_QT编译OpenCV 2.3

首先,我想像我对2.2版本所做的那样,它对我来说效果很好。为此,我遵循了本指南: http://knowtheabc .wordpress.com/2011/02/25/windows-opencv-and-qt-creator/

  • 下载源代码
  • 设置 CMake 并告诉它创建MInGW Makefiles 并在我的 C:\Qt... 路径中指定了 g++.exegcc.exeqmake.exe 的路径,检查WITH_QT并生成发布的Makefiles。
  • 使用 mingw32-makemingw32-make install 在 shell 中构建并安装它

成功完成后,我只需要将路径添加到我的“.pro”文件中并能够构建一些使用 OpenCV 的优秀软件(回到我使用 2.2 版本的时候)。基本上最后一部分在这里描述:http://knowtheabc.wordpress。 com/2011/02/25/opencv-in-qt/

所以我对 2.3 版本进行了相同的尝试,它与旧版本一样编译成功。它甚至构建了我的示例程序,但一旦我执行它,它就会再次关闭并返回: -1073741515

第二次尝试:使用 MinGW 来使用预构建的 OpenCV superpack

作为第一种方法不起作用我尝试使用预构建版本。虽然这些没有启用WITH_QT,但我仍然想尝试一下。

所以我下载了超级包,解压并将其放在某个地方。然后,我想做与之前相同的操作,并将包含文件夹的路径和 dll 添加到我的“.pro”文件中:

INCLUDEPATH+= C:/workspace/opencv/OpenCV2.3/build/include
LIBS+= C:/workspace/opencv/OpenCV2.3/build/x64/mingw/bin/*.dll

作为编译器,我使用当前 Qt SDK 附带的 MinGW 编译器。但这在构建时崩溃了:

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”文件中的路径:

LIBS+= C:/workspace/opencv/OpenCV2.3/build/x64/vc9/bin/*.dll

但这也会崩溃,并出现无法读取 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.

所以这里是我的设置:

  • Win7 Professional x64
  • 安装了最新的 Qt SDK (4.7.1)。 3)
  • OpenCV 2.3 版本

有人知道这里可能出了什么问题吗?很高兴获得任何帮助!

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:

First try: Compiling OpenCV 2.3 with WITH_QT

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/

  • Downloaded the source code
  • Set up CMake and told it to create MInGW Makefiles and specified the paths to the g++.exe, gcc.exe and qmake.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 and mingw32-make install

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/

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

Second try: Using the pre-built OpenCV superpack using MinGW

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.

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

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

Third try: Just like the second, but with using the VC2008 compiler

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

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
  • Latest Qt SDK installed (4.7.3)
  • OpenCV 2.3 release

Does anybody have an idea what might be wrong here? Would be glad for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聆听风音 2024-12-01 18:21:03

我刚刚让我的 QT 4.7.3 可以与 OpenCV2.3 一起使用。不幸的是我必须安装 VC++2008 Express Edition 和 Microsoft 的 CDB 调试器(两者都是 Microsoft 的免费赠品)。
好的部分是我现在可以在 IDE、VS 2008 和 Qt Creator 中为 Opencv 进行开发。

这些是我的 .pro 文件的设置:

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 编译器

我已经尝试过我不知道有多少种不同的方法可以使其与 MinGW 一起使用,但到目前为止还没有正确的方法。
我也在 Windows 7 64 位中...但我正在开发 32 位,我想如果我使用 x64 库,我可能会得到 64 位项目。

祝你好运,

安德烈斯

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.

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

Remember, select the MSVC compiler in your Projects Settings

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.

Good luck,

Andres

错々过的事 2024-12-01 18:21:03

显然,

我今天也遇到了 -1073741515 错误。
事实证明,问题与我在发布文件夹中的 Qt dll 有关。...我仍在使用 mingw32 版本,而不是 msvc2008 版本。因此,我将 msvc2008 dll 文件复制到我的 Release 文件夹中,最终成功运行了我的 Qt 应用程序。

Evident,

I got as far as the -1073741515 error also today.
It turned out that the problem was related to the Qt dlls which I had in the release folder.... I was still using the mingw32 versions and not the msvc2008 ones. So I copied the msvc2008 dll files to my Release folder and I finally managed to run my Qt app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文