OpenCV 2.1.0 with Visual Studio 2010

by Agus Kurniawan 23. June 2010 00:24

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. Two months ago OpenCV released the new version of OpenCV 2.1. On this article, I would like to share how to use OpenCV with Visual Studio 2010.

System Requirements

  • Download OpenCV 2.1 or the latest, [V]
  • Download Visual Studio 2010, you can download an express edition [V]

I use Windows 7 x64 as development environment.

OpenCV 2.1 Installation

After you downloaded OpenCV library. Click setup file and then you’ll get a dialog as below

inst1

Click Next button

inst2

Click I Agree button

inst3

Choose Do not add OpenCV to the system PATH (you may choose any option) and then click Next button

inst4

Choose Destnation Folder that you want to store OpenCV files. After that, click Next button

inst5

Click Next button

inst6

Select the type of install Full. After that click Install button. Installer will install OpenCV library on your system.

inst7

Click Finish button to finish installation process.

Now you can see OpenCV 2.1 on your system. You can check on folder where OpenCV installed

openCV

Visual Studio 2010 Project Configuration

After you created a C/C++ project on Visual Studio 2010 you should configure OpenCV on Visual Studio 2010. Open properties dialog of project. Assume your OpenCV 2.1 installed on C:\OpenCV2.1

On properties dialog, click C/C++ –>General and entry C:\OpenCV2.1\include\opencv in Additional Include Directories

conf1

On properties dialog, click C/C++ –>Advanced and select Compile As. If you prefer C compiler, use Compile as C Code (/TC) 

conf2

On properties dialog, click Linker –>General and entry C:\OpenCV2.1\lib in Additional Library Directories

conf3

On properties dialog, click Linker –>Input and entry all *.lib files in Additional Dependencies. If you’re running on debug mode, try to entry all *d.lib files

 conf4

conf5

After you do all tasks above, click OK button on Propeties dialog.

Testing

For testing purpose, try to write this code (*note* change image file c:/temp/monas.jpg)

#include <stdio.h>
#include <highgui.h>
int main( int argc, char** argv ) 
{	
	IplImage* img = cvLoadImage( "c:/temp/monas.jpg",1 );
	cvNamedWindow("Monas", CV_WINDOW_AUTOSIZE );
	cvShowImage("Monas", img );
	cvWaitKey(0);
	cvReleaseImage( &img );
	cvDestroyWindow("Monas");
} 

Compile and run it. If success, you get image viewer dialog as below

monas

when you run this code from Visual Studio  and get error as below. Try to copy *.dll from OpenCV (C:\OpenCV2.1\bin) on folder where your executable file was located

error

Tags:

C/C++ | OpenCV

Comments (6) -

leonardosalvatore
leonardosalvatore Italy
8/19/2010 11:35:45 PM #

Hi,
all is good but i have to add also this folder C:\OpenCV2.1\include\opencv in the C\C++ Additional Include.
I'm on a Win7 64 vs2010 ultimate.

in any case, ty.

wingdf1000
wingdf1000 Hong Kong S.A.R.
9/12/2010 3:53:49 PM #

i followed the steps, but the last step
"Try to copy *.dll from OpenCV (C:\OpenCV2.1\bin) on folder where your executable file was located"
i put the dll to the relative folder
but an error message 0xc0150002 is pop out.
how can i solve it ?
plz

Gabriel
Gabriel Brazil
9/22/2010 12:40:09 AM #

Hi! I have the same error as wingdf1000! I followed all the steps but it gives me an error when I try to execute the program.

Gabriel
Gabriel Brazil
9/22/2010 12:23:20 PM #

I found the problem. You have to download and install Microsoft Visual C++ 2008 Redistributable Packages to work with the 2010 version. Hope it helped!

priit
priit Estonia
1/10/2011 10:58:34 PM #

Gabriel, just did what u suggested and nothing happend. Still getting that error. Im using win xp and vs2010 express. ):

Christophe
Christophe Netherlands
1/23/2011 10:24:35 PM #

I created a video tutorial on building and configuring OpenCV 2.1.0 with TBB support for Visual Studio 2010 http://www.youtube.com/watch?v=XeBhwbRoKvk

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading