VS2017 build OpenCV environment (novice detailed tutorial)

The overall process is as follows:

  • Download Visual Studio2017 version

  • Download OpenCV3.4.1 version

  • Configuration environment variable

  • The introduction of header files, library files, link libraries in the Visual Studio2017

  • Environmental Testing

Description: There is no need to download the appropriate version according to the blog bloggers blog, just change things a little bit between the different versions can be


1, download and install VS2017

Installation Guide Reference blog https://blog.csdn.net/qq_36556893/article/details/79430133

VS includes a variety of workloads, you can check on demand, if only C ++ function only need to check the use of C ++ desktop development


2, the installation package download OpenCV

OpenCV official website https://opencv.org/  select OpenCV3.4.1 version

3, configure the environment variables

Unzip the downloaded files to the specified folder, opencv folder *** opencv \ build \ x64 \ vc14 \ bin path to add a system environment variable

*** represents the file path you have unzipped

Right-click on this computer, select Add the environment variable flow properties as shown below

Note: After you add the path to remember point OK, OK and will be able to point out in full click on it again!

4, introduced in the header file in Visual Studio2017, library files, link libraries

New VS, processes following FIG.

Right newly created project and select Properties

VC ++ directory containing the input directory →

D:\OpenCV\opencv\build\include
D:\OpenCV\opencv\build\include\opencv
D:\OpenCV\opencv\build\include\opencv2

VC ++ library directory, enter the directory →

D:\OpenCV\opencv\build\x64\vc14\lib

Linker → → additional input dependency input

opencv_world341d.lib
opencv_world341.lib

分别代表debug版本和release版本

5、环境测试

右键源文件→添加→新建项

选择C++文件

在运行代码前将预编译头改为不使用预编译头

右键项目名称→属性→预编译头

输入测试代码,如下

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat img = imread("E:/myFile/picture/kobe.jpg");
    //注意这里面的文件路径应该为左下划线(/)或者为双右下划线(\\)
    if (img.empty())
    {
        cout << "无法打开图片!" << endl;
        return -1;
    }
    namedWindow("image", CV_WINDOW_AUTOSIZE);
    imshow("image", img);

    waitKey(0);
    return 0;
}

由于我们使用的是基于64位的

因此将解决方案平台改成x64

运行结果如下图

发布了12 篇原创文章 · 获赞 27 · 访问量 786

Guess you like

Origin blog.csdn.net/Gary_ghw/article/details/102919298