Building OpenCV with Microsoft Visual Studio

The win32 distribution of OpenCV doesnot include the lib files for visual studio compiler. It is necessary to build them from source. The best method to do this is to use CMake. In order to get started with computer vision research with OpenCV successfully the following steps can be followed:-

1. Download and install OpenCV for win32 http://sourceforge.net/projects/opencvlibrary/

2. Install Microsoft Visual Studio (I tested with Visual Studio .NET 2005 and 2008) if not already installed.

3. Download and install CMake http://cmake.org/.

4. Download and install Python. [optional]

5. Generate solution file (.sln) for visual studio with CMake. See the following screenshots.

Select the directories.
Generate .sln file.
6. Build the libraries with visual studio by opening the .sln file and then pressing F7.

7. The lib files are now at PATHTOBUILD\lib\debug or PATHTOBUILD\lib\release depending on the configuration you select from visual studio. For every new OpenCV project configure to point to this directory for libs. Also add Project>Properties->linker->Input->Additional Dependies: cv200d.lib cvaux200d.lib cvhaartraining.lib cxcore200d.lib cxts200d.lib highgui200d.lib ml200d.lib opencv_ffmpeg200d.lib

8. Set Project>Properties->C/C++->General->Additional Include Directories: PATHTOOPENCV\include\opencv

9. Add PATHTOBUILD\bin\debug to system PATH from control panel. Control Panel>System->Advanced->Environment Variables->System variables->Path->Edit.

10. Create a new project and test the following code:

You can download the visual studio .net 2005 project folder with debug build from here. Note: The code was taken from the official OpenCV book. Change the path to image in the code to match one of your existings.

Advertisement
  1. #1 by Saman on March 26, 2011 - 9:37 pm

    Hello,
    I exactly did the same thing up here.after linking the libraries to my new project ,I have errors when I compile the project. It says that stdafx.h can not be found.when I download the .h file and put it in the right place then another .h file can not be found.it doesn’t end.there are thousands of include files which can bot be found.Please help if U could.

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.