Sie sind auf Seite 1von 4

VisualC++_VS2008 - OpenCV Wiki

1 of 4

http://opencv.willowgarage.com/wiki/VisualC++_VS2008

OpenCV 2.1.0 with Visual Studio 2008


These instructions were tested with Visual C++ 9.0 (as part of Visual Studio 2008 Professional). These instructions should work without
modification with Visual Studio 2005 and 2003. Modifications may be necessary for Visual Studio Express editions. These instructions do not
apply to Visual Studio 2010 which uses different settings (see VisualC++).
There exists a short walkthrough video on YouTube at

http://www.youtube.com/watch?v=9nPpa_WiArI

Install OpenCV
1.

Download the OpenCV 2.1.0 Windows installer from SourceForge - "OpenCV-2.1.0-win32-vs2008.exe".

2. Install it to a folder (without any spaces in it), say "C:\OpenCV2.1\". This article will refer to this path as $openCVDir
3. During installation, enable the option "Add OpenCV to the system PATH for all users".

Configure Visual Studio


1. Open VC++ Directories configuration: Tools > Options > Projects and Solutions > VC++ Directories
2. Choose "Show directories for: Include files"
1. Add "$openCVDir\include\opencv"
3. Choose "Show directories for: Library files"
1. Add "$openCVDir\lib"
4. Choose "Show directories for: Source files"
1. Add "$openCVDir\src\cv"
2. Add "$openCVDir\src\cvaux"
3. Add "$openCVDir\src\cxcore"
4. Add "$openCVDir\src\highgui"

Configure your Project


After you've created a project you'll need to add the OpenCV dependencies.
1. Open Project Properties: Project > %projectName% Properties...
2. Open Linker Input properties: Configuration Properties > Linker > Input
3. Open the "..." window to edit "Additional Dependencies" and on each line put:
1. "cv210.lib"
2. "cxcore210.lib"
3. "highgui210.lib"
4. And any other lib file necessary for your project
4. Your project should now build. If you get any errors try restarting Visual Studio and then doing a clean Rebuild.

OpenCV 1.x with Visual Studio 2003


The set of instructions below is tested with Visual C++ 2003. It will also work with some modification under Visual C++ 6.0 and Visual C++
2005, 2008 Express Edition.
To create your own OpenCV-based project in Visual Studio do the following:
Linking DLLs:
To permanantly include necessary dll files, add "C:\OpenCV1.0\bin" to PATH by visiting Advanced tab in System of Windows (the locate of
directory might be different).
One can just copy necessary dll files into project directory with source files.
It might be required to restart Visual C++ when execution of instance failes after successful build.
Customize Global Options:
Open the Visual C++ .Net Application. In the menu bar, select Tools->Options
In the listing, choose Projects->VC++ Directories.
First, select Library files from the "Show Directories for" List Box.
Click the Insert New icon, and locate the folder where you have installed opencv.
Consider that it is installed in "C:/OpenCV1.0".
In the Library files list, locate and add:
"C:\OpenCV1.0\lib"

21/09/2012 19:32

VisualC++_VS2008 - OpenCV Wiki

2 of 4

http://opencv.willowgarage.com/wiki/VisualC++_VS2008

Now choose Include files in the list box, and locate and add the following directories:
"C:\OpenCV1.0\cv\include"
"C:\OpenCV1.0\cxcore\include"
"C:\OpenCV1.0\otherlibs\highgui"
"C:\OpenCV1.0\cvaux\include"
"C:\OpenCV1.0\otherlibs\_graphics\include"

Next, choose source files in the list box, and locate and add the following directories:
"C:\OpenCV1.0\cv\src"
"C:\OpenCV1.0\cxcore\src"
"C:\OpenCV1.0\cvaux\src"
"C:\OpenCV1.0\otherlibs\highgui"
"C:\OpenCV1.0\otherlibs\_graphics\src"

Now click OK in the Options dialog.


You have successfully configured the global settings.
Create New Project:

21/09/2012 19:32

VisualC++_VS2008 - OpenCV Wiki

3 of 4

http://opencv.willowgarage.com/wiki/VisualC++_VS2008

Within Developer Studio create new application:


Select from menu "File"->"New..."->"Projects" tab.
Choose "Win32 Application" or "Win32 console application" - the latter is the easier variant and both the sample projects have this type.

Type the project name and choose location


Click Ok.. In the Application Wizard, Just click Finish.

After the above steps done Developer Studio will create the project folder (by default it has the same name as the project), <project
name>.vcproj file, Solution <project name>.sln and, Three Source files: <project name>.cpp, stdafx.cpp and stdafx.h. StdAfx files are
precompiled header files, which can be very useful if you want to reduce the compilation time.
For example, consider that we have created a new "Hello" Project. Open the Hello.cpp file, and include the OpenCV-related #include directives:
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

Note that these should be included after stdafx.h or you may get build errors.
Now Type some OpenCV code, and Build the Solution by pressing the F7 Key. There should be linker errors.
Add dependency projects into workspace
Choose from menu: "Project" -> "Properties".
Choose "Linker" tab -> "Input" category -> "Additional Dependencies:". Add the paths to all necessary import libraries (cxcore[d].lib cv[d].lib
highgui[d].lib cvaux[d].lib cvcam[d].lib)
Note: The debug versions are available only when you Build the Visual C++ .NET solution provided with the OpenCV installation.

21/09/2012 19:32

VisualC++_VS2008 - OpenCV Wiki

4 of 4

http://opencv.willowgarage.com/wiki/VisualC++_VS2008

If the build process complains about a missing 'windows.h' header file, then you'll need to install the latest version of the
SDK.
. That's it!.. Now Build and Run the application using F5 key and enjoy OpenCV!

Microsoft Windows

.
If you have any queries regarding this, try posting at

OpenCV Yahoo! Groups.

.
All the Best!
Paramesh.
Modified by Seongjoo 2008-06-13

OpenCVWiki: VisualC++_VS2008 (last edited 2010-08-02 01:18:46 by ShervinEmami)

21/09/2012 19:32

Das könnte Ihnen auch gefallen