Starting with OpenCV

OpenCV  Logo
I installed OpenCv (Windows) and compiling my first code was not as easy as I expected.
Basically my %OPENCV_DIR% environment variable didn’t work and this is a work around.

 

 

 


First check were is OpenCV installed and your Microsoft Visual Studio version.

Depending on your Visual Studio version, you should later direct Visual Studio to a different folder following this logic:

  • vc8 → Visual Studio 2005
  • vc9 → Visual Studio 2008
  • vc10 → Visual Studio 2010
  • vc11 → Visual Studio 2012
  • vc12 → Visual Studio 2013

In my case, since I have Visual Studio 2012 I will use:

%OPENCV_DIR%\x64\vc11\bin

Got to: My Computer > System Properties > Advanced System Settings > Environment Variables > System variables > add a new system variable:

Name: OPENCV_DIR
Value: D:\opencv\build\x64\vc11\bin\ (change this to your OpenCV folder)

Go to: My Computer > System Properties > Advanced System Settings > Environment Variables > System variables > select the variable named Path and press Edit button to add:

 ;%OPENCV_DIR%\   (or x86 if you're not on a 64bit PC)

RESTART  your computer and then you’re ready to start a project on Visual Studio.


Right-click on your project and then on properties.

[IMG]

After that you have 5 modifications to do:

[IMG]

  1. C++ > General >> Additional Include Directories > add:
$(OPENCV_DIR)\..\..\include
  1. Linker > General >>  Additional Library Directories > add:
$(OPENCV_DIR)\lib
  1. Linker > Input >> Additional Dependencies > add:
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib

Check the lib names for your OpenCV version
  1. Linker > Input >>Use Library Dependency Inputs >> Yes

If you’re compiling on a x64 machine you should need to change that too.

  1. Still on Property Pages, click on “Configuration Manager ..” button on top right corner and change platform to x64.

 

Now you’re done and really for some image processing!

If this doesn’t work try change the environment variable $(OPENCV_DIR to a hard-coded OpenCV location.

Advertisements
This entry was posted in C++, Computer Stuff, OpenCV, Programming and tagged , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s