SoFunction
Updated on 2024-11-13

windows 10 configured to use openCV 4.3.0 under visual studio 2019

openCV is a powerful image processing library based on C++. The library is often used when processing images or videos in C++, but it is not a standard library in C++, so you need to download it and load and configure it into your project before you can use it.
So how do you configure it? First you have to have all the following tools.

  • Windows 10 system. It can be installed via image or via CD or USB flash drive.
  • Visual Studio 2019, based on practical (saving) use (money), I'm using the free version of COMMUNITY.Click here to download and install.

Click on community2019 in the download below and then install it, please refer to the other tutorial examples for specific steps.

After installing visual studio is to install opencv, opencv in writing this blog when the latest version of 4.3.0, so change the tutorial to 4.3.0 as an example, other versions of the installation of the same way.opencv can be downloaded by clicking here

After the download is complete, directly double-click the exe file to extract the compiled file can be, after the installation of the exe will have the following files, in which the build folder saves the main use of the function code block, the source folder saves the relevant documents and other necessary files.


The next step is to configure the installation path of opencv into the environment variable. Add the bin path in vec15 in the x64 folder under the build folder in opencv to the environment variable as shown below in the address in my opencv:


Copy the above address and add it to the environment variable. Note that windows 10 environment variables are divided into system environment variables and user environment variables, it depends on your visual studio environment variables are in which one. For security reasons, it is recommended to add them all, as shown below:


Just double click, create a new one, and paste the address.

Now everything is ready, only owe...nothing, next open visual studio to create a basic C++ project, then change some configuration can write opencv code. Click create new project, find C++ console application (empty project can also be), and enter a project name and project address, the following two steps:


After clicking Create, you need to configure the dependencies required by opencv. Click on the view, find the "Property Manager" in "Other Windows", click on it and the property manager will appear in the right sidebar. Double click on the project name, then find the VC++ directory and change the "Library directory" and the include directory to the library directory and the include directory of the address where opencv is located (just click Edit), as shown below:


Note: It is a good idea to add both to the include directory, the address where include is located and the address where opencv2 is located in the include folder.


So let's have fun writing the code, oh no, there is one last step. Configure additional dependencies in the linker, which are the "opencv_worldxxxd.lib" files in the lib folder at the same address as the bin folder, where xxx is the version (e.g. 4.30, xxx is 430, followed by d for debug), and if it's a release, you can just remove the d. If it is a release version, just remove the d.


This time, you can really enjoy knocking the code, knocking the code of the first step is to first include the header file. opencv in a few important header file is:


After you have included these header files, you can introduce the cv namespace by using namespace cv (or by adding a cv:: in front of every object or function you need to use in the cv library).

So then look at a simple opencv example, just simply display a picture, the picture in opencv is the Mat object. The code is as follows:

#include <iostream>
#include<opencv2/core/>
#include<opencv2/highgui/>
#include<opencv2/imgproc/>

using namespace cv;

int main()
{
  Mat example = imread("F:\\xxxxx\\"); //Photo address
  if (()) {
    std::cout << "ERROR!" << std::endl;
    exit(EXIT_FAILURE); //If the read is unsuccessful, interrupt the program directly to avoid causing unpredictable exceptions in the subsequent code.
  }
  imshow("My professional photo.", example);
  waitKey(0); //Don't forget this line, otherwise the photo will flash, here indicates how long the window is paused, in milliseconds, 0 means permanently

}

It is displayed as follows:
Of course you guys won't be able to see this picture, handsome professional photos can't be freely shown to everyone (arrogant face).

It's all done here, so go write your own code happily!

What, you still ran into the following error?


This is because you are not using x64 mode but x86 mode, just change the mode in the picture


What, you ran into the following error again?


This is because of the use of relative paths, go to the properties of the linker in the input dependency of the project can be changed to an absolute path, as follows:


The next thing you know, it's not a big deal.

to this article on windows 10 in visual studio2019 configuration using openCV4.3.0 article is introduced to this, more related to vs2019 configuration using openCV4.3.0 content, please search for my previous posts or continue to browse the following related articles I hope that you will support me more in the future!