3

Visual Studio 2019配置OpenCV开发环境

 2 years ago
source link: https://xugaoxiang.com/2019/12/10/visual-studio-2019-opencv/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

软硬件环境

  • Visual Studio 2019
  • OpenCV 4.1.2
  • Windows 10

视频看这里

Visual Studio 2019

官方链接下载安装文件,安装完Visual studio 2019后,再选择安装相应组件,这里需要安装c++桌面应用组件,见下图

0650753f4b0fe3e9.png

配置opencv环境

opencv下载地址,最新版本4.1.2,https://github.com/opencv/opencv/releases/tag/4.1.2,下载下来后是一个exe文件,双击选择安装目录,比如这里我是D:\xugaoxiang,最后目录结构是这样的

1cc152a622eb454a.png

接下来设置环境变量PATH,鼠标右键点击我的电脑 --> 属性 --> 高级 --> 环境变量

a3a4939757382fba.png

在Visual studio中使用opencv

在准备工作完成后,就可以打开visual studio 2019了,我们来新建一个项目,类型选择c++控制台应用

489e8387a9e19f07.png

4bf2da2e67a7ce23.png

在工程创建成功后,在源文件OpenCVTest.cpp中加入代码

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat image = Mat::zeros(300, 600, CV_8UC3);
    circle(image, Point(300, 200), 100, Scalar(0, 255, 128), -100);
    circle(image, Point(400, 200), 100, Scalar(255, 255, 255), -100);
    imshow("Show Window", image);
    waitKey(0);
    return 0;
}

然后依次点击项目 --> OpenCVTest项目属性

26774a22bd2de1fd.png

接下来设置opencv头文件及库的路径

8f202555c1cf1ac2.png

7d467c29a662841a.png

一定要确保新增成功了

aa6f95e52cb570bf.png

接下来设置模块依赖

d5ede72f7fd90549.png

eee0bb1b2a35c708.png

最后设置解决方案平台为x64

ee8761dd873664a6.png

到这里,一切就都准备好了,按下F5键运行工程

67eb91f87883a56b.png


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK