Installing and configuring OpenCV 2.0 on Windows

Installing the latest OpenCV might seem intimidating to you. After all, you need to compile all that source code and generate libraries and executables yourself. So here's a little guide to take you through.

Step 1: Install OpenCV 2.0

Go to the SourceForge page of OpenCV and install OpenCV 2.0. If you check the directory you installed the things in, you see that there a folder called src. We need to use that compile OpenCV.

Step 2: Install CMake

CMake is a cross platform "make" (the linux make). You can download it for free here. With CMake, you can use the command line interface. Or, if you want, a GUI that makes life easier.

Step 3: Compile everything

Once you install, start up the command line prompt. (Win+R, type cmd and press enter). Type cmake and you should be able to see something on screen.

Next, type in this line:

cd C:\\OpenCV2.0
mkdir build
cd build
cmake -D:CMAKE_BUILD_TYPE=RELEASE C:\\OpenCV2.0

You'll see a lot of things happening. And after a while, the process would complete, and you'd have a Visual Studio Project for OpenCV.

Step 4: Compile the project

This one is simple. Double click the OpenCV project, and compile it. It'll take a lot of time. Compiling the samples and the entire library itself takes a real long time.

Now, the following folders contain what we want

  • C:\OpenCV2.0\src\lib\Debug
  • C:\OpenCV2.0\src\bin\Debug

All the .lib and .dll files have been generated in those folders.

Step 5: Configuring OpenCV in VisualStudio

Now we need to tell Visual Studio where these newly generated files .lib are. So open up the Options dialog box (Tools > Options) and select the VC++ Directories tab as shown below:

Now we'll add to the Executable Files, Include Files, and Library Files.

Add C:\OpenCV2.0\src\bin\Debug to the Executable Files.

Add C:\OpenCV2.0\include\opencv to the Include Files.

Add C:\OpenCV2.0\src\lib\Debug to the Library Files.

Step 6: Testing the installation

Just to test that OpenCV is working, we'll create a simple "Hello World!" program. You can have a look at that program here: Hello World! with Images.

Just get the entire code done, and return back to this article.

[get the code now :P]

Now that you have the code, we need to tell Visual Studio that we need to use the OpenCV libraries. So open up the Project properties (Project > [project name] Properties). Then go to Configuration Properties > Linker > Input and add the following into Additional dependencies:

cv200d.lib cxcore200d.lib highgui200d.lib cvaux200d.lib ml200d.lib

Next, take all the .dll files in C:\OpenCV2.0\src\bin\Debug directory and copy them into C:\Windows\System32. On most systems, this will work. If not, try copying them into C:\Windows as well.

(Thanks for Shaurya for pointing out ml200d.lib library)

Done!

If everything worked, you just got a working OpenCV 2.0 installation :) Enjoy!

If you were following the Beginner's guide to OpenCV, go to the next part: Hello World! with Images!



Utkarsh Sinha created AI Shack in 2010 and has since been working on computer vision and related fields. He is currently at Carnegie Mellon University studying computer vision.