OpenCV download, installation and configuration

Step 1: Download and install the OpenCV SDK:

There is only the fifth step between different versions - the configuration of the link library is different, just change the corresponding version number (such as 460 of OpenCV4.6.0 to your own corresponding version number).

First enter the official website Home - OpenCV , the interface is shown in Figure 1.1

Figure 1.1

Click Library--Release to download the opencv corresponding to the operating system. The windows version I downloaded here is shown in Figure 1.2.

Figure 1.2

After downloading, get the file "opencv-4.6.0xx.exe", as shown in Figure 1.3. After the download is complete, OpenCV can be installed and configured. Rather than installation, it is more appropriate to call it decompression, because the .exe installation file we downloaded is just a self-extracting program. After double-clicking the file, the program will prompt us to decompress it to a certain location, and then click the [Extract] button in the pop-up dialog box.

Figure 1.3

After decompression, an opencv folder will be generated under the specified path, which contains two subfolders named build and sources. Among them, the build folder contains related files that support OpenCV, and the sources contain OpenCV source code and related files.

Step 2: Configure environment variables:

The configuration method is as follows:

[Computer]--[(Right-click) Properties]--[Advanced System Settings]--[Environment Variables]--path, add the corresponding path in the variable value, such as adding "...opencv\build\x64\vc15 \bin”(x64 indicates that the operating system environment is 64-bit system, if it is installed on a 32-bit system, it should be x86; VC15 indicates that the compilation environment is vs2017, VC10 is equivalent to VS2010, VC11 is equivalent to VS2012, twelve is equivalent to VS2013, if VS If the version is different, you can check it on Baidu and download the corresponding opencv.) As shown in Figure 2.1, environment variables have been added.

 Figure 2.1

 Step 3: Configuration of the project include directory

First, create a new project on VS, [New] - [Project] - [Windows Desktop] - [Windows Desktop Wizard], select the path, click OK, as shown in Figure 3.1

Figure 3.1

After entering the next interface, click Empty Project--Confirm. Right-click on [Source Files] in the Solution Explorer--Add--New Item, and prepare to create a new cpp source file in the project. Select [C++ file (cpp)], name it, such as "main", and then click [Add], a new .cpp file will be added to the project, as shown in Figure 3.2.

 

 Figure 3.2

 In the menu bar, click 【View】-【Other Windows】-【Property Manager】, as shown in Figure 3.3 and 3.4, it will be displayed. As shown in Figure 3.5, first double-click [Microsoft.Cpp.x64.user] or right-click the property operation to open the most common property page of the project. After opening the property page, first add the following directory in [General Properties]--[VC++ Directory]--[Include Directory], as shown in Figure 3.6, add the file as shown in the figure (the path when decompressing opencv).

 

 Figure 3.3

Figure 3.4 

Figure 3.5 

 

 Figure 3.6

Step 4: Configuration of the project library (lib) directory

The fourth step is similar to the third step. Also add this path  in [General Properties]-[vc++ Directory]-[Library Directory] . Here, if the compiler chooses win32, use x86; if the compiler chooses x64, use x64. As shown in Figure 4.1.

 Figure 4.1

Step 5: Configuration of link library

Also in [General Properties] - [Linker] - [Input] - [Additional Dependencies], add the lib package as shown in Figure 5.1 (change 460 to your own opencv version), pay attention to some tutorials It is to directly add opencv_world460d.lib. I will report an error at the time, so I can write the full path. Of course, I can try both ways. But it should be noted that it seems that the low version of opencv needs to add a lot of libs. This can be directly searched on Baidu, such as "OpenCV2.4.9 configuration", and directly copy the blogger's lib. In addition, if you check your decompression path, you will find that there are two libs. One of the file libraries ends with d is the debug version, and the other without d ends is the release version. Add additional dependencies according to your own situation.

 Figure 5.1

Step Six: Test

The test process is to load and display a picture into the window with OpenCV. Use VS to create a new cpp file and enter the following code:

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{     Mat img = imread("1.jpg"); //Read a picture     imshow("【Loaded Picture】", img); //Display the loaded picture in the window     waitKey( 6000); //The window closes automatically after waiting for 6000ms }



I put a picture named 1.jpg in the project directory (same path as the cpp source file), and then run it. If the configuration is successful, no error will be reported, and a console and a picture window will be obtained.

For more questions, please refer to the book "Introduction to OpenCV3 Programming_Edited by Mao Xingyun_Electronic Industry Publishing".

 

Guess you like

Origin blog.csdn.net/qq_43593751/article/details/127926222