In Window, install OpenCV tutorial in Visual Studio 2022 (C++) environment
This tutorial is mainly for the convenience of Xiaobai to install the C++ version of OpenCV.
1. Step 1: Download the official OpenCV
and install it locally. Remember the installation path, it will be needed later!
2. Configure system environment variables, add new variables in Path. That is, the path of opencv installation, select build/x64/vc15/bin in opencv
3. Install visual studio 2022, directly from the official website
, and install it according to the C++ configuration.
4. Configure the environment in visual studio.
(1) Create a C++ project
(2) Right-click the project and click Properties, as shown in the figure below.
(3) Add the path to the include directory in the VC++ directory: \opencv\build\include (find it under the Opencv path you installed) (4)
Add the path to the library directory in the VC++ directory: \opencv\build\x64\ vc15\lib (find it under the Opencv path you installed yourself)
(5) Additional dependencies in the input under the linker: opencv_world.460.lib or opencv_world.460d.lib
Note: The two are different, opencv_world.460.lib is in In visual studio, when running, select release; opencv_world.460d.lib is in visual studio, when running, select Debug.
5. So far the configuration is complete, write the test code and test.
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("C:\\Users\\86159\\Desktop\\cat.jpg");
namedWindow("测试");
imshow("测试",img);
waitKey(0);
return 0;
}