Configure OpenCV for Visual Studio

  • Set Environmental Path for OpenCV:
  1. OPENCV_DIR->D:\opencv\build\x64\vc14
  2. add bin directory to “path”->D:\opencv\build\x64\vc14\bin
  • Include directory


  • Library(Linker->input->Additional Library Directories)


Linker->input->debug mode


Linker->input->release mode


OpenCV: 2.4.5

1)  Extract opencv contents in a directory of your choice (But do not extract it in a directory too deep)

  • I chose “D:\“, so all my opencv folders are now in “D:\opencv\

2) Set Environmental Path for OpenCV:

  • In order to make your settings portable and somehow more efficient, you must define a folder path for opencv so that you wouldn’t enter its directory address statically every time.
  • Right click on “My Computer” and go to: Properties -> Advanced System Setting -> Advanced ->  Environment Variables and under the “System Variables” choose “New” and use these:
    * Variable Name: OPENCV_DIR
    * Variable Values: “D:\opencv\build\x64\vc10
    * Note:D:\opencv” is where you have extracted your opencv folders and “x64″ depends on your OS type.
    * You could navigate to this folder and copy the address from address bar.
    * There is also a “\vc11” folder but I have no idea what it’s for, maybe new test versions.
  • Now that you have set the environmental path, you can start visual studio.

3) Include Libraries: You’ll need to set library and header file addresses for Visual Studio so that it understands your “include“s and can use dynamic linking libraries (DLLs).

  • First of all, you should know the difference between Debug and Release options, But if you don’t, it doesn’t matter right now but be sure to look for them later
  • After starting Visual Studio, create a sample Win32 console application (C++).
  • Select View -> Property Manager and then again View -> Property Pages and open Configuration Properties window.
  • Select C/C++ -> General
  • Edit the “Additional Include Directories” and add “$(OPENCV_DIR)\..\..\include“. By this way, we could include both the “opencv” and “opencv” folder
  • If you notice, these setting are going under Active (Debug) configuration! Remember to repeat steps 3 to 5 for Release option, too!.

4) Linker Settings: As I mentioned before you should set linking directories for the linker:

  • Get to Configuration Properties window as described in step 3.
  • Choose Linker -> General and edit Additional Library Directories. Add the following directory: “$(OPENCV_DIR)\lib“.

  • Choose Linker -> Input and add the following libraries to Additional Dependencies:
    • opencv_core245d.lib
    • opencv_imgproc245d.lib
    • opencv_highgui245d.lib
    • opencv_ml245d.lib
    • opencv_video245d.lib
    • opencv_features2d245d.lib
    • opencv_calib3d245d.lib
    • opencv_objdetect245d.lib
    • opencv_contrib245d.lib
    • opencv_legacy245d.lib
    • opencv_flann245d.lib
  • Important Note!!!: “245” changes according to your OpenCV version. For example if you have OpenCV 2.3.1 you must change all “245“s to “231“.
  • Another Note!!: “d” at the end of library names is for Debug mode. As I said before, you must repeat steps 3 to 5 for Release mode, too. But remember to omit the ending “d” for release mode.
  • Example: If you have OpenCV 2.3.1 and you are setting up Release mode, the last library name would be: “opencv_flann231.lib”

5) Set the Platform: If your target Machine (OS) is x64 or x86, you should make changes to your project accordingly so that it runs properly.

  • Go to Configuration Properties window again and click the Configuration Manager button.
  • Under Active solution platforms, choose your target platform.
  • If you can’t see your target platform, under Active Solution Platforms, select New and define your Platform (Itanium x86 or x64). Mine would be: x64; Copy Settings from Win32.
  • Note: Again, in this window you should apply these settings to both Debug and Release.

6) Test Your Settings:  Now that you have set up these configurations it’s time to test them.

  • Go to your opencv directory and then samples -> cpp -> tutorial_code -> ImgProc and copy the contents of Smoothing.cpp to your projects.
  • Remember to copy “lena.png” from images in your working directory or address it correctly.

7) If there are any problems please let me know.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s