简体   繁体   English

Windows上具有Qt Creator的OpenCV 2.1

[英]OpenCV 2.1 with Qt Creator on Windows

I have OpenCV 2.1 and Qt (Creator) installed on Windows. 我在Windows上安装了OpenCV 2.1和Qt(创建器)。
Using the OpenCV C API I can link, build and run apps in Qt using OpenCV. 使用OpenCV C API,我可以使用OpenCV在Qt中链接,构建和运行应用程序。
However, the when using the OpenCV C++ API, I am getting linking problems. 但是,当使用OpenCV C ++ API时,出现链接问题。
This is probably due to C++ ABI problems, since I'm using the pre-built binaries (built with MSVC-2008) for Windows and Qt Creator uses MinGW. 这可能是由于C ++ ABI问题造成的,因为我在Windows上使用了预构建的二进制文件(由MSVC-2008构建),而Qt Creator使用的是MinGW。
How do I configure CMake to rebuild OpenCV 2.1 so that the resulting .lib s are compatible with Qt? 如何配置CMake来重建OpenCV 2.1,以使生成的.lib与Qt兼容?
Thanks! 谢谢!

The simplest way is to do one of these: 最简单的方法是执行以下操作之一:

Option 1: You use the Qt SDK+mingw: go to the qt install directory and open a Qt command prompt. 选项1:您使用Qt SDK + mingw:转到qt安装目录并打开Qt命令提示符。 This will add you mingw toolchain to your PATH. 这会将您的mingw工具链添加到PATH中。 Add the cmake binary to your PATH: (only an example, real directory might differ) 将cmake二进制文件添加到PATH :(仅作为示例,真实目录可能有所不同)

set PATH="C:\Program Files\CMake\bin;%PATH%

Option 2: You use a standalone installation of mingw: Either go to the mingw install directory and doubleclick the mingw32vars.bat or similar. 选项2:您使用mingw的独立安装:转到mingw安装目录,然后双击mingw32vars.bat或类似文件。 A command prompt should pop up and gcc should be in PATH. 应该会弹出一个命令提示符,并且gcc应该在PATH中。 If there is no such file, open a command prompt: type cmd in the windows search bar (Vista/7) or type cmd in the Run command dialog. 如果没有这样的文件,请打开命令提示符:在Windows搜索栏中键入cmd (Vista / 7)或在“运行命令”对话框中键入cmd Add mingw to PATH yourself (again, example directory, might differ on your system): 自己将mingw添加到PATH(同样,示例目录在您的系统上可能有所不同):

set PATH=C:\MinGW\bin;%PATH%

Common second step: Download the OpenCV sources, extract them somewhere and cd to that directory with your command prompt. 常见的第二步:下载OpenCV源代码,将其解压缩到某个位置,并使用命令提示符将cd到该目录。 Ensure all tools can be found in PATH by running these commands: 通过运行以下命令,确保可以在PATH中找到所有工具:

cmake --version
gcc -v

These should report some info on the programs. 这些应该报告有关程序的一些信息。 If one command returns "Command not found" or similar, you haven't set up your PATH correctly. 如果一个命令返回“找不到命令”或类似命令,则说明您没有正确设置PATH。

Compiling OpenCV: I understand from your question that the OpenCV library you're trying to use is built using CMake. 编译OpenCV:我从您的问题中了解到,您要使用的OpenCV库是使用CMake构建的。 From your command prompt (which now is set to the OpenCV source directory), do the following: 在命令提示符(现在设置为OpenCV源目录)中,执行以下操作:

mkdir build
cd build
cmake .. -G"MinGW Makefiles"
mingw32-make

This should build the library in the "build" subdirectory. 这应该在“ build”子目录中构建库。 If there are any errors related to cmake or mingw32-make, that would be problems for OpenCV. 如果存在与cmake或mingw32-make相关的任何错误,则对于OpenCV来说将是问题。

您需要使用可在qt ftp站点上找到的预构建的MinGW二进制文件。

You need to make sure that CMake will find the same MinGW that was used to compile Qt. 您需要确保CMake将找到用于编译Qt的同一MinGW。 If you downloaded the QtCreator bundle, you should have a mingw directory in Qt installation directory. 如果下载了QtCreator捆绑软件,则Qt安装目录中应该有一个mingw目录。 Make sure that this directory is in your path and that the correct version of MinGW will be used (for example using the command "which"). 确保此目录在您的路径中,并且将使用正确版本的MinGW(例如,使用命令“ which”)。 Another alternative is to configure the CMake variable CMAKE_CXX_COMPILER so that it points to the correct executable in the mingw directory. 另一种选择是配置CMake变量CMAKE_CXX_COMPILER ,使其指向mingw目录中的正确可执行文件。

After that, all you need to do is run CMake in your OpenCV folder, telling it to generated MinGW makefiles, then run make and you're done (hopefully)! 之后,您要做的就是在OpenCV文件夹中运行CMake,告诉它生成MinGW makefile,然后运行make,就可以完成了(希望如此)!

This post shows step by step how to install Qt on Windows and how to compile OpenCV 2.3.1 with MingW and integrate it with Qt-Creator. 这篇文章分步显示了如何在Windows 上安装Qt以及如何使用MingW编译OpenCV 2.3.1并将其与Qt-Creator集成。

It provides screenshots and videos for orientation. 它提供了屏幕截图和视频以进行定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM