visual studio2022 uses c++ to run yolov5 target detection-opencv installation and configuration

I refer to the blog about downloading and configuring OpenCV in visual studio 2022. However, when running the program, different content or errors appear. Let’s record it here to facilitate subsequent verification of errors in subsequent operations.

 I downloaded the opencv4.8.0 Windows version

After the download is completed, you will get the following file.

         Next, change the environment variables. Mine is a Windows 11 system. I can't find the advanced system settings by right-clicking on the computer -> Properties. Finally, I found the system properties through Settings -> System Information -> Advanced System Settings, as shown below. Click on the environment variables. , in the page that opens, find the Path in the system variable, double-click to open it, click New on the right, and copy it according to the address of the downloaded opencv.

 Open the downloaded Visual Studio2022 and click to create a new project, as shown in the figure

 Fill in the location according to the location you want to create.

 After filling in, right-click the source file to add a new item

 After the file is created, click Properties in the project on the menu bar. You need to modify 3 positions.

 1. The include directory in the VC++ directory; 2. The library directory in the VC++ directory; 3. Additional dependencies entered in the linker; the specific modifications are as follows: Here is an example of a library directory, and the same is true for include directories.

 Fill in the two addresses installed by opencv.

 Additional dependencies in the linker input require filling in the absolute path to the item plus .lib. Mine is this address D:\opencv\opencv\build\x64\vc16\lib\opencv_world480d.lib

 After filling in, click OK

 Run this program to see if the opencv installation is successful.

#include <opencv2\opencv.hpp> 
#include <iostream>

using namespace std;   // c++标准库中所有标识符都被定义于一个名为std的namespace中
using namespace cv;

int main()
{
	Mat img = imread("C:/Users/ly351/Pictures/test1.jpg");
	if (img.empty())
	{
		cout << "该图片读取有问题" << endl;
		return 0;
	}
	imshow("test", img);
	waitKey(0);
	return 0;
}

 Read successfully. This picture is a picture I found randomly on the Internet. If it involves infringement, I'm sorry, please contact me to delete it immediately.

Guess you like

Origin blog.csdn.net/weixin_50847463/article/details/132020752