1. Software preparation
2. Environment configuration
Note: The paths used in all processes of environment configuration are the paths corresponding to personal download and installation software! !
2.1 System environment configuration
[Advanced System Configuration] - [Environment Variables] - [System Variables-Path]
Double-click [Path], click [New] after entering, enter the path shown in the red box (please note to change the path to your own installation path), click [OK] to complete the system environment configuration, it is recommended to restart the computer to continue the subsequent operations.
E:\OpenCV\opencv\build\x64\vc16\bin
E:\OpenCV\opencv\build\x64\vc16\lib
2.2 Configure the environment in VS
First create an [empty project]
Right-click the source file and click [Add] - [New Item]
Right-click the project name [OpenCV666] - [Properties]
Add the path in [VC++ Directory] - [Include Directory] as follows:
E:\OpenCV\opencv\build\include
E:\OpenCV\opencv\build\include\opencv2
Add the following path in [Library Directory]:
E:\OpenCV\opencv\build\x64\vc16\lib
Click [C/C++] - [General] - [Additional Include Directory]
Enter the following path:
E:\OpenCV\opencv\build\include
E:\OpenCV\opencv\build\include\opencv2
Click [Linker] - [Input] - [Additional Dependencies]
Enter the name in the red box, be sure to add .lib as well
Finally, click [Apply] in the lower right corner to complete the environment configuration!
3. Environmental testing
After the environment configuration is completed, use the following code to test
#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img; //定义一个Mat变量存储图像
img = imread("E:/OpenCV/OpenCV666/picture/testpic01.jpg"); //读取图片,图片路径记得改一下
imshow("test", img); //显示图片
waitKey(0); //窗口等待
}
The results of successful operation are as follows:
Note that the path in img=imread in the test must also be set to your own photo path~