Win10+VS2019+OpenCV compilation and configuration

According to more than N tutorials found on the Internet, it finally compiled and ran successfully. Record it here for the convenience of the next operation.

1. First of all, by default, you have downloaded VS2019 and installed  desktop development using c++.

OpenCV version 4.5 download  OpenCV download , Baidu network disk link: https://pan.baidu.com/s/1EgQwOlyK1mZj_hl9YsDHDA Extraction code: z2p1 

Find the downloaded file, double-click to install (this is actually a decompression process)

 

 

Select the decompression directory, click Extract to automatically create a folder named opencv under the selected path. The decompressed content is as follows:

 

 

Next, add the following environment variables to the computer, Path in the system variables (need to be modified according to your own installation path):

My own is E:\opencv\build\x64\vc15\bin

After the environment variables are configured, restart the computer.

2. Configure OpenCV in VS2019

First open VS2019, create a new project, select C++, empty project.

Enter the project name and location of the project, click Create

Right click on the project name, select properties

Click the VC++ directory on the left , select X64 as the platform, and pay attention to the include directory and library directory on the right

First modify the containing directory, select it and click Edit

Click on the folder sign New and select Directory

Add two variables as shown in the figure below, click OK

E:\opencv\build\include

E:\opencv\build\include\opencv2

Add library directory (operation as above) add E:\opencv\build\x64\vc15\lib

Finally add Modify Additional Dependencies

Add a variable (manual input or paste)

opencv_world450d.lib   , click OK (here I am using Debug, if using Release, change to opencv_world450.lib  )

                                                                                                                                  

   

Finally, test whether the configuration is successful

Right click on  the source file  , Add -> New Item

                                                                                                                     

Select the C++ file and enter the name  main

                                                                                    

Add the following code (just paste it directly)

#include<opencv2/opencv.hpp>

#include<iostream>

using namespace cv;

int main(int argc, char** argv) {

	Mat image = imread("F:/1.jpg");

	if (image.empty()) {

		printf("could not load image...\n");

		return -1;

	}

	//namedWindow("test_opencv_setup", 0);

	imshow("test_opencv_srtup", image);

	waitKey(0);

	return 0;

}

Configure Cuda 

Reference  https://blog.csdn.net/fengxinzioo/article/details/109402921

Note: The ffmpeg and ippicv files that need to be downloaded when compiling versions above opencv4 are replaced into the .cache folder after downloading, rename and add the corresponding MD, and cmake will not have a warning again.

Update 2020-11-30  

 4.5

4.5 All cached files to be downloaded are uploaded to the network disk Link: link
Extraction code: n2kc 

The principle is the same as above.

I found a lot of articles, only this one is simple, and the others are limited and I can't understand it.

Guess you like

Origin blog.csdn.net/qq_23879197/article/details/110127459
Recommended