Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Click Edit, and then click New to add a new environment variable. Here, paste in the path if the bin folder inside your Open CV package. If you extracted the package in your root directory the path should be something like: C:\opencv\build\x64\vc14\bin

Press OK and then OK again to exit the environment variable dialog.


4) Get started with a project in Visual

...

Studio 


Open up Visual Studio ( ⊞Win → start typing "Visual Studio" → press enter).

...

Now, paste the following code to your main.cpp-file in your Visual Studio project:

Code Block
languagecpp
firstline1
linenumberstrue
#include<opencv2/opencv.hpp>
#include<iostream>


using namespace std;
using namespace cv;
int main()
{
  Mat img = imread("

...

lena.jpg");
  namedWindow("image", WINDOW_NORMAL);
  imshow("image", img);
  waitKey(0);
  return 0;
}

...

languagecpp
firstline1
linenumberstrue




If you get lots of red lines, don't worry, it is supposed to be like that. Continue to the next and final step!

5) Link Open CV to Visual Studio and test your program

Finally we have to link Open CV with Visual Studio. 

First of all, make sure you are in the Debug environment with the x64-version. The fields for these settings are found in Visual Studio's header bar.

Moving on.

Right click on your project again and go to Properties

In the menu on the left side, go to C/C++ → General. Inside Additional Include Directories paste the path to the include folder of your Open CV package: C:\opencv\build\include. Press Apply

Go back to menu on the left. Go to Linker → General. Inside Additional Library Directories paste the path to the lib-files of your Open CV package: C:\opencv\build\x64\vc14\lib. Press Apply

Back to the menu on the left. Go to Input. Edit Additional Dependencies and paste the .lib-file's name. For our configuration this file is "opencv_world411d.lib" (if your Open CV package is version 4.1.1, "d" stands for Debug mode). Press Apply.

Exit Properties by pressing OK.


You are now ready to test your code! Press Ctrl + Shift + B  to build the code. You should now get the output "Build Succeeded". 

Run the Local Windows Debugger (In the header bar with a green arrow as symbol). This should display the lena-image in a new screen. (Pressing any key would make the window close.)

If this happens it means that you successfully installed Open CV C++ with Visual Studio on your Windows PC.


Good luck! 

...