In Window, install OpenCV tutorial in Visual Studio 2022 (C++) environment (without Cmake version)

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
insert image description here
and install it locally. Remember the installation path, it will be needed later!
insert image description here
2. Configure system environment variables, add new variables in Path. That is, the path of opencv installation, select build/x64/vc15/bin in opencv

insert image description here
3. Install visual studio 2022, directly from the official website
insert image description here
, 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.

insert image description here
(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)
insert image description here
(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.

insert image description here
insert image description here
insert image description here
insert image description here
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;
}

insert image description here

Guess you like

Origin blog.csdn.net/weixin_50918736/article/details/130176469