You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Here is a simple step-by-step tutorial to installation and configuration of Open CV with C++ and Visual Studio 15.
This installation guide is bas(ically identical to)ed on this guide found online: https://www.deciphertechnic.com/install-opencv-with-visual-studio/


1) Install Visual Studio 15

 From this page. Download the excution file and run it. The installer is self-explaining, just keep the express settings, pressing "next" all the time.


2) Install OpenCV

From this page. I recommend you to install the latest stable version (Open CV - 4.1.1  04.10.2019) . Press the big button saying "Windows" to download the executable file. Run the file. I highly recommend you to extract the Open CV package in your root directory (C:/).


3) Add Open CV to system PATH


Press the Windows-button (⊞) on your keybord, type "Advanced System Settings" and go to these settings. Further navigate to Environment Variables > System Variables > Path

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).

Create a new project as a Win32 Console application using Visual C++. Choose Empty Project and press Finish.

Press Ctrl + Shift + A and add a new Source file to your project and name it "main". This will open up your new cpp-file in the editor.

Right click on your project in the Solution Explorer and press Open Folder in File Explorer. Add a new folder and name it "data". Then save the picture below as a jpg-file and name it "lena".

Image result for lena image


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

#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;
}



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! 





  

  • No labels