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:
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.
After that you have 5 modifications to do:
- C++ > General >> Additional Include Directories > add:
- Linker > General >> Additional Library Directories > add:
- 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
- Linker > Input >>Use Library Dependency Inputs >> Yes
If you’re compiling on a x64 machine you should need to change that too.
- 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.