OpenCV with VS2008

To create your own OpenCV-based project in Visual Studio do the following:

Linking DLLs:

  • To permanantly include necessary dll files, add “C:\Program Files\OpenCV\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:/Program Files/OpenCV”.
  • In the Library files list, locate and add:

“C:\Program Files\OpenCV\lib”


  • Now choose Include files in the list box, and locate and add the following directories:

“C:\Program Files\OpenCV\cv\include”
“C:\Program Files\OpenCV\cxcore\include”
“C:\Program Files\OpenCV\otherlibs\highgui”
“C:\Program Files\OpenCV\cvaux\include”
“C:\Program Files\OpenCV\otherlibs\_graphics\include”


  • Next, choose source files in the list box, and locate and add the following directories:

“C:\Program Files\OpenCV\cv\src”
“C:\Program Files\OpenCV\cxcore\src”
“C:\Program Files\OpenCV\cvaux\src”
“C:\Program Files\OpenCV\otherlibs\highgui”
“C:\Program Files\OpenCV\otherlibs\_graphics\src”


  • Now click OK in the Options dialog.
  • You have successfully configured the global settings.

Create New Project:

  • 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.


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

Compiling.jpg .

Post quoted from: openCV Wiki, all copyrights reserved by original authors.

Author: Andol Li

A HCI researcher, a digital media lecturer, an information product designer, and a python/php/java coder.

15 Comments On “ OpenCV with VS2008”

  1. Is there any way to include all the headers, linker dependencies, etc by default? For example, I create a lot of small projects that use openCV. I don’t want to go through all the steps of including headers, dependencies, etc. When I create a new project, I want all these to be included by default. I’m using VS 2010 Ultimate.

  2. Hello Andol,

    When I install OpenCV2.4.2,I followed the following process.
    1)Extracted OpenCV files to C:\
    2)Configure and build OpenCV with visual studio 2008 using Cmake.
    3)Add libraries to Visual Studio.
    That is in this video:

    >>Is this process correct(video and mentioned steps) ?
    >>Are there any other methods to install and configure OpenCV with VS2008 on windows with out using Cmake ?
    >>If there,what is that?
    I must be thankful 2 u if u reply.

    Thank U.

    • @bestelec
      an alternative to install latest version of openCV in windows is to use pre-compiled version – this version can be installed as normal applications and its codes are all compiled already.

  3. Hello Andol,
    Actually I’m new to all OpenCV stuff.Even I can’t run this simple sample program.When I debug this it shows this

    message:-The program ‘[384] OpenCV_Hello-World.exe: Native’ has exited with code -1 (0xffffffff).

    This is sample program:-
    using namespace cv;
    using namespace std;
    int main( int argc, char** argv )
    if( argc != 2)
    cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
    return -1;
    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
    if(! ) // Check for invalid input
    cout << "Could not open or find the image" << std::endl ;
    return -1;
    namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image ); // Show our image inside it. waitKey(0); // Wait for a keystroke in the window
    return 0;
    Please tell me which lines should I change to show the image.

    Please Reply,
    Thank U.

  4. @bestelec
    the code you made should be run in command lines – as the code needs to read the target image path from the command in argv[1].

    this can be simplified as below:
    #include your headers here
    using namespace std;
    using namespace cv;
    Mat img = imread(“c:/lena.jpg”,0);
    namedWindow(“show”, 0);
    imshow(“show”, img);
    return 0;

  5. Thanks for ones marvelous posting! I seriously enjoyed reading it, you happen to be a
    great author. I will be sure to bookmark your blog and will come back later in
    life. I want to encourage yourself to continue your great
    job, have a nice afternoon!

  6. Just wish to say your article is as astounding.
    The clearness to your submit is just excellent and that i could assume you’re an expert in this subject.
    Fine with your permission allow me to take hold of your feed to keep up
    to date with approaching post. Thanks a million and please keep up the enjoyable work.

Leave a comment
Due to technical adjustments, the comment function is shortly closed and will be re-openning soon. Thanks.

Copyrights 2006-2017 © All rights reserved
Theme Tree2, re-designed by Andol Li, powered by WordPress and Bootsrap
WWW.ANDOL.ME | 浙ICP备15040508号-1
公安备案图标 浙公网安备33010602004018号
Back to top