March 08, 2014

OpenCV on Visual Studio 2013

Questions:
- How to start OpenCV with VC++
- How to create a new opencv project in VS2013
- How to configure Visual Studio 2013 for OpenCV
- Why i can't config windows and visual studio for start with OpenCV

Configure Windows:
Follow these steps
1- My Computer > Properties > Advanced System Settings > Environment Variables > New and add new system variable
Name: OPENCV_DIR
Value: C:\opencv\build\ (or other path that you like)

2- My Computer > Properties > Advanced System Settings > Environment Variables... > System variables > select Path and press Edit button
and add ;%OPENCV_DIR%\x86\vc12\bin

PS: for Visual Studio 2013 add ;%OPENCV_DIR%\x86\vc12\bin
PS: for Visual Studio 2012 add ;%OPENCV_DIR%\x86\vc11\bin




Configure Visual Studio Project:
1- Add new Visual C++ Project from File > Project... > Visual C++ > Win32 Console Application and select a name for your project and press OK and finished

2- Go to Solution Explorer > select Project and right click > Properties > Configuration > and select All Configurations

3- In left tree menu select Configuration Properties > C/C++ > General > Additional Include Directories > Add $(OPENCV_DIR)\Include in right section


3- In left tree menu select Configuration Properties > C/C++ > Linker > General > Additional Library Directories > Add $(OPENCV_DIR)\x86\vc12\lib in right section

PS: Please choose right item based on your visual studio
$(OPENCV_DIR)\x86\vc12\lib or
$(OPENCV_DIR)\x86\vc12\lib or
$(OPENCV_DIR)\x86\vc12\lib 
you can find version of visual studio in Configuration Properties > General > Platform Toolset

3- In left tree menu select Configuration Properties > C/C++ > Linker > Input > Additional Dependencies > select Edit and add below lib files

opencv_calib3d248d.lib
opencv_contrib248d.lib
opencv_core248d.lib
opencv_features2d248d.lib
opencv_flann248d.lib
opencv_gpu248d.lib
opencv_haartraining_engined.lib
opencv_highgui248d.lib
opencv_imgproc248d.lib
opencv_legacy248d.lib
opencv_ml248d.lib
opencv_nonfree248d.lib
opencv_objdetect248d.lib
opencv_photo248d.lib
opencv_stitching248d.lib
opencv_superres248d.lib
opencv_ts248d.lib
opencv_video248d.lib
opencv_videostab248d.lib

PS: Above file names are consist of opencv_ + name of library + version of OpenCV and d for Debug library edition

PS: Before add these items open 
C:\opencv\build\x86\vc10\lib or
C:\opencv\build\x86\vc11\lib or
C:\opencv\build\x86\vc12\lib 
based on your Visual Studio and select right names

PS: You can change Configuration in top left of Property Pages and select Release and add with 'd' Library to your release project

opencv_calib3d248.lib
opencv_contrib248.lib
opencv_core248.lib
opencv_features2d248.lib
opencv_flann248.lib
opencv_gpu248.lib
opencv_haartraining_engined.lib
opencv_highgui248.lib
opencv_imgproc248.lib
opencv_legacy248.lib
opencv_ml248.lib
opencv_nonfree248.lib
opencv_objdetect248.lib
opencv_photo248.lib
opencv_stitching248.lib
opencv_superres248.lib
opencv_ts248.lib
opencv_video248.lib
opencv_videostab248.lib

PS: all these libraries (lib files) are not required and you can choose your required library

Explanation:
- Microsoft Windows 8.1
- Visual Studio 2013 (v120)

5 comments:

Sergio Martini Popoli said...

Thanks. There are some errata, but your tutorial is very appreciated =)

innovativeitsolutions2 said...

Innovative IT solutions helps freshers and experienced graduates and post graduates in getting placed in IT companies.

Sankalp Chugh said...

thank you for this tutorial. I am using opencv 2.4.9, so some lib have changed
I could not find
*opencv_haartraining_engined.lib*
and instead i found a new lib
*opencv_ocl249d.lib*

updated lists of lib
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

Anonymous said...

how to add OpenCV in JavaScript project?

Anonymous said...

Thank you! Works ok (with some lib updates).