Setup Opencv-2.3 For Visual Studio 2010

Setup OpenCV-2.3 for Visual Studio 2010

Well, the official guide is for installing OpenCV 2.1 on VS2010, so I wrote some instructions below that shows how to properly install and configure the x86 version of OpenCV 2.3 on Visual Studio 2010 (Express), since a lot of folks seem to have problems setting it up correctly.

Download OpenCV-2.3.0-win-superpack.exe and execute it to extract all files to a folder named OpenCV2.3. Inside this folder there are 2 directories: build and opencv. All the setup on VS2010 will refer to the build directory. For practical purposes I moved the folder OpenCV2.3 to my C:\ drive, so pay attention to the paths I suggest on this guide as yours might be different.

On Visual Studio, create a new Win32 Console Application project and name it whatever you like. After that, a new window will show up. Click on the tab Application Settings and make sure the option Empty Project gets selected:

Sample Image

Add a new file main.cpp to the folder Source Files, then add this code to main.cpp:

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: ./opencv_hello <file.png>\n");
return -1;
}

IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (!img)
{
return -1;
}

cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );

cvWaitKey(0);

return 0;
}

At this point, we need to configure the project so it can locate OpenCV headers and libraries. Go to the Project Properties (ALT+F7), and once the new window shows up do the following:

  • On the Configuration box, select All Configurations

  • Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):

    C:\OpenCV2.3\build\include\opencv

    C:\OpenCV2.3\build\include\opencv2

    C:\OpenCV2.3\build\include

Sample Image

Note that include\opencv is for the C interface of OpenCV and include\opencv2 if for the C++ interface. We are also adding the folder include to prevent our build from being broken by some headers of the C interface that refer to C++ headers as opencv2\core.

  • Then, add the path of the libraries on Configuration Properties > Linker > General, and on the Additional Library Directories field, add this: C:\OpenCV2.3\build\x86\vc9\lib:

Sample Image

  • Finally, for this simple test we are going to add the libraries opencv_core230.lib and opencv_highgui230.lib. So go to Configuration Properties > Linker > Input and add them:

Sample Image

When writing more complex applications you'll probably need to add other OpenCV libs that I did not
mentioned on this little project of ours.

Press F7 to Build Solution and you should see:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

To be able to execute the application you'll need to modify the PATH environment variable of your system to add the location of OpenCV's DLLs. Add this to end of PATH:

; C:\OpenCV2.3\build\x86\vc9\bin

Installing OpenCV 2.4.3 in Visual C++ 2010 Express

1. Installing OpenCV 2.4.3

First, get OpenCV 2.4.3 from sourceforge.net. 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 PanelSystemAdvanced system settingsAdvanced Tab → Environment variables...

Sample Image

On the System Variables section, select Path (1), Edit (2), and type C:\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 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 FileNewProject...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 PropertiesVC++ 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 type C:\opencv\build\x86\vc10\lib.

Library directories dialog

Click Ok to close the dialog.

Back to the property dialog, select LinkerInputAdditional Dependencies to add new entries. On the popup dialog, type the files below:

opencv_calib3d243d.lib
opencv_contrib243d.lib
opencv_core243d.lib
opencv_features2d243d.lib
opencv_flann243d.lib
opencv_gpu243d.lib
opencv_haartraining_engined.lib
opencv_highgui243d.lib
opencv_imgproc243d.lib
opencv_legacy243d.lib
opencv_ml243d.lib
opencv_nonfree243d.lib
opencv_objdetect243d.lib
opencv_photo243d.lib
opencv_stitching243d.lib
opencv_ts243d.lib
opencv_video243d.lib
opencv_videostab243d.lib

Note that the filenames end with "d" (for "debug"). Also note that if you have installed another version of OpenCV (say 2.4.9) these filenames will end with 249d instead of 243d (opencv_core249d.lib..etc).

Sample Image

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

NOTE:

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:

opencv_core243.lib

opencv_imgproc243.lib

...

instead of:

opencv_core243d.lib

opencv_imgproc243d.lib

...

You've done setting up Visual C++, now is the time to write the real code. Right click your project and select AddNew 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);
waitKey(0);
}

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.

OpenCV 2.3.1 installation, VS 2010, MEX

It sounds like you didn't build the INSTALL target in Visual Studio. Did you only build ALL_BUILD?

Using OpenCV 2.3.1 with Windows Form Application in visual studio 2010 express

May I suggest Qt instead of windows form application..? It will give you more freedom for future development and at the same time give you the power to go cross-platform. There is a very nice video tutorial on YouTube which you can use as a base. Plus, OpenCV and Qt work very nicely together.

However, if your bigger app needs windows forms, you could follow this tutorial which shows how to integrate OpenCV with windows forms.

HTH

Setup OpenCV in Visual Studio 2010

You haven added the src directory files. Look at this page: http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010

You need to add these folders:
Source Directories... add: 'C:\OpenCV2.1\src\cv; C:\OpenCV2.1\src\cvaux; C:\OpenCV2.1\src\cxcore; C:\OpenCV2.1\src\highgui; C:\OpenCV2.1\src\ml;'

OpenCV 2.3.1 cxcore210.lib and cv210.lib inherited values

Hmmmm seems to work for now, think I managed to find somewhat of a workaround. I went to Linker > Input > Additional Dependencies and unchecked the box "Inherit from parent or project defaults". Both lib files stay listed as inherited values but at least I can properly build and run the project without getting an error telling me to point to cxcore210.lib cv210.lib



Related Topics



Leave a reply



Submit