How to Install OpenCV – Windows

Hi, so I finally got openCV working on my laptop and thought I should keep a record for future references as well as the people who need it. I basically copied the steps from bsdnoobz at StackOverflow who explain so detail and clear. Hope this will work for you guys out there!


1. Installing OpenCV 2.4.3

First, get OpenCV 2.4.3 from Its a self-extracting so just double click to start the installation. Install it in a directory, say C:\.

OpenCV self-extractor

Wait until all files get extracted. It will create a new directory C:\opencv which contains OpenCV header files, libraries, code samples, etc.

Now you need to add the directory C:\opencv\build\x86\vc10\bin to your system PATH. This directory contains OpenCV DLLs required for running your code.

Open Control Panel → System → Advanced system settings → Advanced Tab → Environment variables…

enter image description here

On the System Variables section, select Path (1), Edit (2), and typeC:\opencv\build\x86\vc10\bin; (3), then click Ok.

On some computers, you may need to restart your computer for the system to recognize the environment path variables. ((this is a required step on my machine. You’ll get an error that says “opencv_core240d.dll is missing from the computer” if the path isn’t updated correctly!))

This will completes the OpenCV 2.4.3 installation on your computer.

2. Create a new project and set up Visual C++

Open Visual C++ and select File → New → Project… → Visual C++ → Empty Project. Give a name for your project (e.g: cvtest) and set the project location (e.g: c:\projects).

New project dialog

Click Ok. Visual C++ will create an empty project.

VC++ empty project

Make sure that “Debug” is selected in the solution configuration combobox. Right-click cvtest and select Properties → VC++ Directories.

Project property dialog

Select Include Directories to add a new entry and type C:\opencv\build\include.

Include directories dialog

Click Ok to close the dialog.

Back to the Property dialog, select Library Directories to add a new entry and typeC:\opencv\build\x86\vc10\lib.

Library directories dialog

Click Ok to close the dialog.

Back to the property dialog, select Linker → Input → Additional Dependencies to add new entries. On the popup dialog, type the files below: (if you are using different version of OpenCV than version 2.4.3, you have to change 243 to your version number -> so if you’ve got version 2.4.5, you would want to say opencv_calib3d245.lib) 


Note that the filenames end with “d” (for “debug”).

enter image description here

Click Ok to close the dialog. Click Ok on the project properties dialog to save all settings.


These steps will configure Visual C++ for the “Debug” solution. For “Release” solution (optional), you need to repeat adding the OpenCV directories and in Additional Dependencies section, use:


instead of:


You’ve done setting up Visual C++, now is the time to write the real code. Right click your project and select Add → New Item… → Visual C++ → C++ File.

Add new source file

Name your file (e.g: loadimg.cpp) and click Ok. Type the code below in the editor:

#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
    Mat im = imread("c:/full/path/to/lena.jpg");
    if (im.empty()) 
        cout << "Cannot load image!" << endl;
        return -1;
    imshow("Image", im);

The code above will load c:\full\path\to\lena.jpg and display the image. You can use any image you like, just make sure the path to the image is correct.

Type F5 to compile the code, and it will display the image in a nice window.

First OpenCV program

And that is your first OpenCV program!

3. Where to go from here?

Now that your OpenCV environment is ready, what’s next?

  1. Go to the samples dir → c:\opencv\samples\cpp.
  2. Read and compile some code.
  3. Write your own code.