Visual Studio 2022 OpenCV environment construction (C++)

Download the latest version of the runtime from the official website https://opencv.org/releases/

Insert image description here

Unzip to the specified folder

Insert image description here

Add environment variables to the system

Open the Control Panel, enter System Information, and click Advanced System Settings
Insert image description here
Insert image description here

Click on environment variables
Insert image description here

Add D:\OpenCV project\opencv 4.6 runtime\build\x64\vc15 (OpenCV runtime path) to the Path environment variable
Insert image description here

Insert image description here

Visual Studio project configuration

Create a C++ console application
Insert image description here

Enter the property manager
Insert image description here

Configure Debug|x64
Insert image description here

VC++ directory
include directory added:
D:\OpenCV project\opencv 4.6 runtime\build\include
D:\OpenCV project\opencv 4.6 runtime\build\include\opencv2
Insert image description here


Add D:\OpenCV project\opencv 4.6 runtime\build\x64\vc15\lib to the library directory
Insert image description here

Linker
Enter additional dependency projects to fill in opencv_world460d.lib
Insert image description here

That is, the full file name of the file under this path
Insert image description here

Copy the library files compiled at runtime to the compilation path of the project
Insert image description here

Test opening the picture

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

using namespace std;
using namespace cv;

int main()
{
    
    
    Mat image;
    image = imread("C:\\Users\\Aron\\Desktop\\01\\1.jpg");
    imshow("Test", image);
    waitKey(0);
}

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40671962/article/details/126736555