Setting Up Open CV 2.3 Visual Studio 2010

This tutorial will explain step by step how to setup Visual Studio 2010 with Open CV 2.3 to start programming with this Open CV library.

Step 1

Download OpenCV-2.3.exe from Open CV Downloads

Step 2

Extract all the files to local directory (say d:\) under the name Open cv2.3 or any name by default.

Step 3

Go to Windows path by :
Right Click my Computer > Properties > Advance System Settings > Advance > Environment Variables > choose the path variable and modify it with your
opencv bin directory as :

Step 4

Open Visual Studio and create a new project as :

Step 5

Create a new empty console application as :

Now Our project is ready and let’s add main.cpp in Source files of the project folder as :

Step 6

Write down following code to display an image in main.cpp

#include "cv.h" //main OpenCV functions
#include "highgui.h" //OpenCV GUI functions¯include <stdio.h>
int main()
	/* declare a new IplImage pointer, the basic
	image data structure in OpenCV */
	IplImage* newImg;
	/* load an image named "desert.jpg", 1 means
	this is a color image */
	newImg = cvLoadImage("Desert.jpg",1);
	//create a new window
	cvNamedWindow("Window", 1);
	//display the image in the window
	cvShowImage("Window", newImg);
	//wait for key to close the window
	cvDestroyWindow("Window"); //destroy the window
	cvReleaseImage(&newImg); //release the memory for the image
	return 0;

After saving this file you will see lot of underlined red lines on this file. This is because now opencv is not fully configured. Let’s Do it :

Step 7

Right Click on project and open the properties page as :

Step 8

Go to : Configuration Properties > C/C++ > General > Additional Include Directories
add 3 folders where your opencv filder is extracted on drive as :

Step 9

Go to : Linker > General > Additional Librarary Directories and include the lib directory as :

Step 10

Go to : Linker > Input > Additional Dependencies and add all or the files you want to add as :

All the files are located in your D:\OpenCV2.3\build\x86\vc10\lib directory. Compile your program and image will be displayed