Tuesday, January 18, 2011

open cv

OpenCV Installation Guide
This guide describes how to install and link the OpenCV library 2.1 together with Visual Studio 2008 in order to compile the lab projects developed for this course. Once this process has been completed, full control over the OpenCV library files will be available.
Notes:
  • OpenCV is an evolving project, therefore new iterations of the software will be released in the future. However as the software changes many of the installation steps demonstrated in this document will be the same or will get simpler
  • Building the OpenCV libraries with the Intel IPP will not be covered in this guide, however information on this topic can be found at http://software.intel.com/en-us/articles/intel-ipp-support-model-changed-in-opencv-2x/
  • The compiler that is used in this installation guide is Visual C++ 2008 Express Edition.

1) Installing VS2008 Express
  1. Download Visual C++ 2008 Express Edition from http://www.microsoft.com/express/Downloads/#2008-Visual-CPP
  2. Install Visual C++ 2008 Express Edition


2) Installing OpenCV 2.1
    1. Download OpenCV 2.1 as shown in the image below from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.1/
    2. When installing OpenCV 2.1, make sure that the files are added to the system path for all users
    3. After Installation is complete restart computer.




3) Linking OpenCV 2.1 with Visual C++
  1. Open Visual C++
  2. Open Tools --> Options. Under Projects and Solutions --> VC++ Directories
  3. Select Show directories for: Library files and create a new line with the location of the OpenCV lib folder that was specified during installation
  1. Select Show directories for: Include files and create a new line with the location of the OpenCV include\opencv folder that was specified during installation

4) Test Project
To make sure that everything is functional, a test project will be created to use OpenCV to display an image included in OpenCV sample programs.
  1. Open Visual C++
  2. Go File->New->Project
  3. When the New Project dialog appears select Win32 Console Application and enter a project name
  4. Make sure that your project is empty
  5. Add a .cpp file to you project called main.cpp
  6. Press Alt+F7 or select from the tool menu Project->"your projects name" Properties
  7. Open Configuration Properties->Linker->Input
  8. Beside Additional Dependencies add cv210.lib highgui210.lib cxcore210.lib




  1. Copy the following code into main.cpp
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>

using namespace cv;

int main()
{
char img_file[] = "C:\\OpenCV2.1\\samples\\c\\lena.jpg";


IplImage* img = cvLoadImage(img_file);
cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);
cvShowImage("Example1",img);

cvWaitKey(0);

}
  1. Compile and execute. Congratulations you have just written your first OpenCV program!

No comments:

Post a Comment