Working with OpenCV in Visual Studio in Windows-7

Hi everyone, I finally found how to work with OpenCV in VS-10 after a long search and big research made in Internet, no one has solved my problem like the below link did.

This tutorial is inspired by

Lets get started,

1. Download OpenCV for Windows from official site, then extract the files to your C:\ drive ( Can be extracted to any drive, for simplicity and remembering the things, go for C:\ drive)

2. Set the class path, go to "My Computer" -> right click  -> "Properties" -> "Advanced System settings" -> go to Advanced tab -> select Environment Variables -> select  "path" under "System Variables" and add following to path variable without modifying it, put semicolon (;) at the end of the path and add,

64-Bit users add,


32-Bit users add,

See figure(1).

3. Open visual studio 2010 and create a new visual c++ win32 console application project, give a name to it.

*NOTE*: Step 4 is only for 64-bit users.

4. Only for 64-bit users,

Select the “Project” Menu and click on “Properties”.
Click on the “Configuration Manager”
Select the “Active Solution Configuration” as “Release”
Select the “Active Solution Platform” and click on it.
And in that Select the new platform as “X64", click on “ok” and close the configuration manager. 

5. For 32-bit users,

Go to project properties, in properties window,
Select the “Configuration Properties” >> “C/C++” >> “General” and in that edit the “Additional Include libraries” by adding these two lines to it:



Here we are adding path to include folders,make sure the path is correct as per drive where you extracted your OpenCV.

*Important*: Select the “Configuration Properties” >> “C/C++” >> “Preprocessor” and in that select, “Preprocessor definition”, edit it by adding this to it :

6. Now in the properties window,
Select the “Configuration Properties” >> “Linker” >> “General” and select and edit the “Additional Library Directories”

64-Bit version users add this line to it:

32-Bit version users add this line to it:

Make sure the path to lib is correct as per your settings.

Select the “Configuration Properties” >> “Linker” >> “Input” and click on “Additional dependencies” and edit it:

Add all the libraries in the library folder if it necessary for your project.

*NOTE*: In opencv_core249.lib, 249 is the version of the OpenCV you have downloaded, make sure it matches with the version of the OpenCV you people have downloaded. You can verify it in C:\OpenCV\build\x86\vc12\lib.

Click apply, OK.

7. Type your source code in main.c (your source file) and run the source in release mode.

*NOTE*: Don't forget to add, #include “stdafx.h” in all the source files you run including the header files OpenCV requires.

This is how you I ended up running OpenCV code with Visual Studio in Windows 7.

Happy coding......!
Thanks :)

Popular posts from this blog

Installing OpenCV-2.4.9 in Windows 7 for Android - Detailed Explanation

Android Custom Navigation Drawer