Installation and configuration of opencv in the vs2019 development environment

Preface

This article mainly describes the configuration of opencv4.5.1 in the vs2019 development environment

1. What is vs?

Introduction: Visual Studio is the most popular integrated development environment for Windows platform applications.
Download address: https://visualstudio.microsoft.com/zh-hans/
Note: This article is based on C++, you need to configure C++ workload when downloading.
vs photo

2. What is opencv?

Introduction: OpenCV is a cross-platform computer vision and machine learning software library released under the BSD license (open source).
Download link: https://opencv.org/releases/
opencv photo

Three, installation steps

1. VS installation steps are omitted, if in doubt, Baidu yourself.

2.opencv4.5.1 installation steps

The installation package is as follows: The
Insert picture description here
execution process is as follows:
2.1: Double-click the exe file, the interface pops up:
After choosing the address you installed, click extract

2.2: After selecting the location where you installed, click extract, and the interface pops up:
Wait until the installation is complete
2.3: After the installation is complete, you can see the folder in the saved address:
opencv folder
2.4: Click the folder, the following result appears, indicating that the installation of opencv4.5.1 is complete :
The installation is complete

Four, configure opencv4.5.1 environment variables

Right-click this computer, open properties, open advanced system settings, select environment variables, find the Path variable in the system variables, double-click -> click New, and set D:\OpenCV4.5.1\opencv\build\x64\ in the opencv folder Add the vc15\bin path, and then confirm it all the way.

Insert picture description here
Insert picture description here
The environment variable configuration is complete.

Five, configure opencv4.5.1 in vs

1. Open vs, create an empty project:

The process is as follows:
Insert picture description here
Insert picture description here
Insert picture description here

2. Click View -> Other Windows -> Property Manager:

Insert picture description here

3. Right-click debug|x64->Properties:

Insert picture description here
Insert picture description here

4. Click on the VC++ directory under General Properties:

4.1. Click Edit under the include directory, and add the path as follows:

Insert picture description here
Copy the path of the above figure into the include directory:
Insert picture description here
4.2. Click Edit under the library directory and add the path as follows:
Insert picture description here
Copy the path of the above figure into the library directory:
Insert picture description here
4.3. Add opencv_world451d.lib to the linker -> input -> additional dependencies
Insert picture description here
Insert picture description here
4.4. Click Confirm after each step is completed.
4.5. Additional: directly right-click the property in the next line of the solution to enter the property configuration.
After finishing all the configuration, let us try it briefly.

Six, simple try

Code block:

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

using namespace cv; //导入cv命名空间
using namespace std;
int main() {
	Mat src = imread("C:\\Users\\ASUS\\Desktop\\1.jpg"); //利用imread读取图片路径
	if (src.empty()) {    //判断是否找到图片,没有就返回Couldn't load image,并退出
		cout << "Couldn't load image\n";
		return 0;
	}
	namedWindow("test opencv setup", WINDOW_AUTOSIZE); //创建一个窗口,自动大小不可人为改变
	imshow("test opencv setup", src);   //窗口显示图片
	namedWindow("output windows", WINDOW_AUTOSIZE); //第一参数窗口名称
	Mat output_image;
	cvtColor(src, output_image, COLOR_BGR2GRAY);  //转换通道,显示灰度值图片
	imshow("output windows", output_image);
	imwrite("C:\\Users\\ASUS\\Desktop\\2.jpg", output_image);
	waitKey(0);  //让窗口停滞

	return 0;
}

Code interface: Insert picture description here
code running interface:
Insert picture description here
special note: here to be modified to X64:
Insert picture description here

to sum up

This article introduces the configuration of opencv4.5.1, if there are any errors, please suggest.

Guess you like

Origin blog.csdn.net/ivan_9/article/details/112984941