OpenCV3.4.0+Visual Studio2017配置

1、安装visual studio2017

这个不用多说,相信大家都会。

2、下载OpenCV

 https://github.com/opencv/opencv/releases/download/3.4.0/opencv-3.4.0-vc14_vc15.exe

从上面的网址下载并安装(其实就是解压缩),我的路径是C:\opencv,安装完毕后该目录下还有build和sources两个文件夹。其中的内容如下:

build:头文件以及编译好的库文件,包括lib和dll。

sources:OpenCV的源代码,可以自己重新进行编译。

3、配置visual studio2017

3.1 新建工程

按照下图所示,建立一个 windows console application

3.2 添加 include路径、lib路径、lib文件

打开新建项目的属性页,如下图所示

3.2.1 添加include路径

选中“Include Directories”属性,添加: C:\opencv\build\include;

3.2.2 添加lib路径

选中“Library Directories”属性,添加: C:\opencv\build\x64\vc15\lib;

3.2.3 添加lib

选中“input”属性,添加: opencv_world340d.lib;

4、测试

4.1 输入代码如下:

该代码源自OpenCV Samples

 1 // OpenCVPrj01.cpp : Defines the entry point for the console application.
 2 //
 3 
 4 #include "stdafx.h"
 5 
 6 #include "opencv2/imgcodecs.hpp"
 7 #include "opencv2/highgui.hpp"
 8 #include <iostream>
 9 
10 using namespace cv;
11 using namespace std;
12 
13 /**
14 * @function main
15 * @brief Main function
16 */
17 int main(void)
18 {
19     double alpha = 0.5; double beta; double input;
20 
21     Mat src1, src2, dst;
22 
23     /// Ask the user enter alpha
24     cout << " Simple Linear Blender " << endl;
25     cout << "-----------------------" << endl;
26     cout << "* Enter alpha [0.0-1.0]: ";
27     cin >> input;
28 
29     // We use the alpha provided by the user if it is between 0 and 1
30     if (input >= 0 && input <= 1)
31     {
32         alpha = input;
33     }
34 
35     //![load]
36     /// Read images ( both have to be of the same size and type )
37     src1 = imread("LinuxLogo.jpg");
38     src2 = imread("WindowsLogo.jpg");
39     //![load]
40 
41     if (src1.empty()) { cout << "Error loading src1" << endl; return -1; }
42     if (src2.empty()) { cout << "Error loading src2" << endl; return -1; }
43 
44     //![blend_images]
45     beta = (1.0 - alpha);
46     addWeighted(src1, alpha, src2, beta, 0.0, dst);
47     //![blend_images]
48 
49     //![display]
50     imshow("Linear Blend", dst);
51     waitKey(0);
52     //![display]
53 
54     return 0;
55 }

4.2 拷贝2张图片(LinuxLogo.jpg和WindowsLogo.jpg)到源文件目录下。

         

 

4.3 工具栏中的“solution platforms”一定要选择“x64”

因为我们以上的设置都是基于x64平台的。opencv-3.4.0-vc14_vc15.exe 这个文件中只有x64的库,如果32位平台的需要自行编译,我会在另一篇文章如何编译OpenCV3.4.0中说明如何自己编译OpenCV。

4.4 运行

4.4.1 按F5或ctrl+F5运行程序,出现如下界面:

4.4.2 输入0-1的数值:

4.4.3 显示图片叠加结果

运行到这一步,表示你已经能够成功的在visual studio 2017 环境中使用OpenCV 3.4.0了。

 

 2018-02-09 18:13:34

 

posted @ 2018-02-09 13:21  上中下,高平宽  阅读(5389)  评论(0编辑  收藏  举报