如何使用 C++、Visual Studio 2017 安装/配置 OpenCV3.2.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43786856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:35:04  来源:igfitidea点击:

How can I install/configure OpenCV3.2.0 with C++, Visual Studio 2017?

c++visual-studioopencvvisual-studio-2017

提问by Vijay Nirmal

I want to use OpenCV in Visual Studio 2017 to do c++ program.

我想在 Visual Studio 2017 中使用 OpenCV 来做 C++ 程序。

To do it, I followed Setting Up OpenCV in Visual Studiovideo. In that, he said vc14 should be set as environmental variables for VS2015. There is no vc16 for VS2017. So how do I do it for VS2017? And are there any other video instruction changes to be made if I am to use VS2017?

为此,我按照在 Visual Studio视频中设置 OpenCV 进行操作。在那,他说 vc14 应该设置为 VS2015 的环境变量。VS2017 没有 vc16。那么我如何为 VS2017 做到这一点呢?如果我要使用 VS2017,是否还有其他视频指令需要更改?

回答by ΦXoc? ? Пepeúpa ツ

Since the Doc from official OpenCV tutorial is outdated, I will suggest:

由于官方 OpenCV 教程中的 Doc 已经过时,我建议:

  1. get VS-2017with full compiler like:

    enter image description here

  2. get the newest CMake(uninstall older versions)

  3. get from github the sourceCode hereand hereand place those in C:/openCV folder, create a BUILD folder there too

  4. open Cmake, select the opencv master folder... in the build write the build directory like:

  1. 使用完整的编译器获取VS-2017,例如:

    在此处输入图片说明

  2. 获取最新的CMake(卸载旧版本)

  3. 从 github此处此处获取源代码并将它们放在 C:/openCV 文件夹中,也在那里创建一个 BUILD 文件夹

  4. 打开Cmake,选择opencv master文件夹...在构建中写入构建目录,如:

enter image description here

在此处输入图片说明

  1. click configure, select visual studio 15 2017 and leave selected "use default native compilers", then press "finish"...
  1. 单击配置,选择 Visual Studio 15 2017 并选择“使用默认本机编译器”,然后按“完成”...

enter image description here

在此处输入图片说明

6.1 now you should see cmake doing its job :)

6.1 现在你应该看到 cmake 完成它的工作:)

enter image description here

在此处输入图片说明

  1. once configuration is done set the opencv extra modules path and click configure again, and when is done click generate! :)

    enter image description here

  2. when generation is done click "open project", this will open a huge project in visual studio named "opencv", now you can close cmake, we dont need that anymore.

  3. now, when the solution is ready, be sure you are in "debug" conf and do right click on "ALL_BUILD" and then "build" (that can take a while) once build succeed change to "release" config and do right click on "ALL_BUILD" and then "build" again.

  4. now,be sure you are in "debug" conf and do right click on "INSTALL" and then "build" (that can take a while) once build succeed change to "release" config and do right click on "INSTALL" and then "build" again.

  1. 配置完成后,设置 opencv 额外模块路径并再次单击配置,完成后单击生成!:)

    在此处输入图片说明

  2. 生成完成后单击“打开项目”,这将在 Visual Studio 中打开一个名为“opencv”的巨大项目,现在您可以关闭 cmake,我们不再需要它了。

  3. 现在,当解决方案准备好时,请确保您处于“调试”配置中并右键单击“ALL_BUILD”然后“构建”(可能需要一段时间)一旦构建成功更改为“发布”配置并右键单击在“ALL_BUILD”上,然后再次“构建”。

  4. 现在,请确保您处于“调试”配置中并右键单击“安装”然后“构建”(可能需要一段时间)一旦构建成功更改为“发布”配置并右键单击“安装”然后再次“建造”。

回答by Martin Zikmund

Additonal tip to the accepted answer - if you get an error like this:

已接受答案的附加提示 - 如果您收到这样的错误:

Invalid escape sequence \ o

无效的转义序列 \o

when you copy and paste the filesystem paths, make sure you use forward slash ( /) instead of backward slash, so

复制和粘贴文件系统路径时,请确保使用正斜杠 ( /) 而不是反斜杠,因此

C:\openCV\opencv_contrib-3.2.0\modules

Must be

必须是

C:/openCV/opencv_contrib-3.2.0/modules

Instead. Otherwise, you will get errors that escape sequence \odoes not exist.

反而。否则,您将收到转义序列\o不存在的错误。

回答by globalex

Previous post is just perfect. VS 2017 has lib version VS141.

上一篇文章简直完美。VS 2017 有 VS141 的 lib 版本。

Just extension of previous.

只是以前的扩展。

8 Step. After the cmake generate the Opencv.sln in build folder. Open this project in VS 2017 Opencv visual studio 2017

8 步。cmake 在 build 文件夹中生成 Opencv.sln 后。在 VS 2017 中打开这个项目 Opencv 视觉工作室 2017

I am using approach first, just DEBUG x64 version

我首先使用方法,只是 DEBUG x64 版本

Opencv visual studio 2017

Opencv 视觉工作室 2017

The output looks like this

输出看起来像这样

Opencv visual studio 2017

Opencv 视觉工作室 2017

After Debug, switch to Release and Build whole solution again. Same for 32 bit version. Your final solution is under install location under build folder. With contrib libs whole process took almost 30 minutes on I7. Just shaking with CMAKE until the zero defects, include what ever FFMPEG, Contrib and other path. Final build in VS 2017.

调试后,再次切换到发布和构建整个解决方案。32 位版本相同。您的最终解决方案位于构建文件夹下的安装位置。使用 contrib libs 整个过程在 I7 上花费了将近 30 分钟。只用 CMAKE 摇晃直到零缺陷,包括任何 FFMPEG、Contrib 和其他路径。VS 2017 中的最终版本。

The whole approach and install of built libs you can find on my blog Here

整个逼近并安装内置库,你可以在我的博客找到这里