学习 OpenCV2 – 配置 Win10+OpenCV2.4.13.6+VS2015+Qt5.9.1(Qt5.12.0)

目录 Content
[hide]

一、安装

1.OpenCV2

官方 V2 最新版本是 2.4.13.6. 下载地址:https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.13/opencv-2.4.13.6-vc14.exe/download (vc14 即 vs2015)。

2.VS2015 和 Qt5.9.1(Qt5.12.0)

安装时VS需要勾选 C++ ,Qt 要勾选 VS2015 x64。

What’s New in Qt 5.12:http://doc.qt.io/qt-5/whatsnew512.html
Qt 5.12 download        :http://download.qt.io/official_releases/qt/5.12/
Qt 5.12 Release          :https://wiki.qt.io/Qt_5.12_Release

3.Qt Debugger

下载 Download Debugging Tools for Windows https://docs.microsoft.com/zh-cn/windows-hardware/drivers/debugger/debugger-download-tools 。如果是Win10,下载 WIndows SDK , 当前版本是 10.0.17763,https://developer.microsoft.com/zh-cn/windows/downloads/windows-10-sdk

4.Image Watch

非常重要的插件,可以在VS中查看 Mat 对象。

Image Watch is a watch window for viewing in-memory bitmaps when debugging native C++ code. 

5.Qt Visual Studio Tools

在Visual Studio中,打开 Tools -> Extensions and Updates ,在线搜索 Qt Visual Studio Tools。使用文档一定要读:http://doc.qt.io/qtvstools/index.html

6. Qt Creator SpellChecker Plugin

/2019/02/qt-creator-spellchecker-plugin

二、问题解决

1.Qt 找不到 rc.exe

在安装了 VS2017 后出现,使用Qt时,找不到 rc.exe ,解决办法,将 C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64 添加到系统变量 PATH 中。

2. 添加 opencv 路径

需要将 C:\OpenCV\build\x64\vc14\bin 添加到系统变量 PATH 中。

3. VS中的 Tab

为了方便程序在不同的 IDE 打开,配置 VS 中的 Tab 为 4个 space

三、IDE 配置

1. Qt Creator 的 pro 文件配置

# for opencv config
# verified
win32{
    INCLUDEPATH += "c:\opencv\build\include"
    LIBS += -L"c:\opencv\build\x64\vc14\lib"

    CONFIG(debug,debug|release) {
        LIBS += -lopencv_core2413d       \
                -lopencv_highgui2413d    \
                -lopencv_imgproc2413d    \
                -lopencv_features2d2413d \
                -lopencv_calib3d2413d    \
    } else {
        LIBS += -lopencv_core2413        \
                -lopencv_highgui2413     \
                -lopencv_imgproc2413     \
                -lopencv_features2d2413  \
                -lopencv_calib3d2413     \
    }
}

## not verified
#linux{
#    INCLUDEPATH += "/usr/local/include"
#    LIBS += -L"/home/Installer/opencv-2.4.13/opencv-2.4.13/lib"

#    CONFIG(debug,debug|release) {
#        LIBS += -lopencv_cored       \
#                -lopencv_highguid    \
#                -lopencv_imgprocd    \
#                -lopencv_features2dd \
#                -lopencv_calib3dd    \
#    } else {
#        LIBS += -lopencv_core        \
#                -lopencv_highgui2    \
#                -lopencv_imgproc     \
#                -lopencv_features2d  \
#                -lopencv_calib3d     \
#    }
#}

 

2. VS2015 的 PropertySheet 配置

系统变量来添加路径,方便以后统一修改。

SETX -m OPENCV_DIR C:\OpenCV\build\x64\vc14

VS2015 的属性管理器在 菜单 View -> Other Windows -> Property Manager 打开,在 Debug | x64 和 Release | x64 上点击右键选择 “Add New Property Sheet…”,然后起个名字比如 Debug_x64_PropertySheet,然后点击右键选择 Property,展开 C/C++ ,编辑 Additional Include Directories ,添加 $(OPENCV_DIR)\..\..\include。然后展开 Linker ,编辑 Additional Library Directories ,添加 $(OPENCV_DIR)\lib 。接着展开 Linker->Input ,编辑 Additional Dependencies ,添加你需要的 *.lib 文件。

以后使用可以使用 Add Existing Property Sheet… 来添加已配置的文件来配置 OpenCV 构建规则,比如 LT 的配置:VS2015 Property Sheet OpenCV

Debug_x64_PropertySheet_OpenCV.props

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>$(OPENCV_DIR)\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>opencv_core2413d.lib;opencv_highgui2413d.lib;opencv_imgproc2413d.lib;opencv_features2d2413d.lib;opencv_calib3d2413d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

Release_x64_PropertySheet_OpenCV.props

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>$(OPENCV_DIR)\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>opencv_core2413.lib;opencv_highgui2413.lib;opencv_imgproc2413.lib;opencv_features2d2413.lib;opencv_calib3d2413.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

延伸阅读

  • Qt配置pro文件以及第三方库
    https://blog.csdn.net/y673582465/article/details/72779400

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.