vendredi 8 février 2013

How to install OpenCV 2.3 on Microsoft Visual C++ Express 2008 (Windows XP)

OpenCV is an open source computer vision library available from here .... The library is written in C and C++ and runs under Linux, Windows and Mac OS X. There is active development on interfaces for Python, Ruby, Matlab, and other languages.  

OpenCV was conceived as a way to make computer vision infrastructure universally available. With the aid of Intel’s Performance Library Team,* OpenCV started with a core of implemented code and algorithmic specifications being sent to members of Intel’s Russian library team. This is the “where” of OpenCV: it started in Intel’s research lab with collaboration from the Soft ware Performance Libraries group together with implementation and optimization expertise in Russia.

For more details of OpenCV, I recommend this book :"Learning OpenCV Computer Vision With The OpenCV Library" which could be found on this link.


This tutorial assumes that you have already installed Microsoft Visual C++ Express 2008 and includes the following steps:
  1. Step1: Downloading and Installing OpenCV OpenCV 
  2. Step2: Include the Bin File and Lib File 
  3. Step3: Configure Visual Studio to use OpenCV 
  4. Setp4:Create a sample project which makes use of OpenCV 2.3

Step1: Downloading and Installing OpenCV 2.3
Go to the folder where you downloaded the executable file and select “Run as Administrator”.
The executable file is essentially an archive of files with an extractor built in. It will ask you to select the location where you would like it to extract all its contents. Select for exemple C:\ as the path and click Extract. It will create a folder called opencv2.3 with the path: C:\opencv2.3

Step2: Include the Bin File and Lib File 
Add the path of the bin and lib file in the ( C:\opencv2.3\build\x86\vc9\lib and C:\opencv2.3\build\x86\vc9\bin ) Environment Variables dialogue (the System Variables box select Path and then Edit).

Step3: Configure Visual Studio to use OpenCV :

* Add Executable, Include and Lib File
This step is done only one time while installing OpenCV Bib:
1- Open Visual C++ Express 2008
2- Go to Tools →  Options → Project and Solution → VC++ Directories
3- Select in the right combox Binary file and add the binary file located in C:\opencv2.3\build\x86\vc9\bin
4-  Select in the right combox Include file and add the three path of Include file located respectively in
      C:\opencv2.3\build\include\opencv
      C:\opencv2.3\build\include\opencv2
      C:\opencv2.3\build\include
5-  Select in the right combox Bib file and add the bib file located in 
     C:\opencv2.3\build\x86\vc9\lib

* Add Lib File
This step is done for every new Visual C++ Project:
 1- Go to Project → Properties  → Configuration properties  →  Liker  → Input  → Additional Dependencies  and add the bib that you are ging to use, for exemple:
  opencv_core231d.lib  opencv_imgproc231d.lib  opencv_highgui231d.lib  opencv_ml231d.lib  opencv_video231d.lib  opencv_features2d231d.lib  opencv_calib3d231d.lib  opencv_objdetect231d.lib  opencv_contrib231d.lib  opencv_legacy231d.lib  opencv_flann231d.lib

2- Click Apply then OK


Setp4:Create a sample project which makes use of OpenCV 2.3
1- Click File → New →Project
2- In the “Installed Templates” box choose Visual C++ → Win32 and select Win32 Console Application
3- Enter a name for the project and specify  the location where you would like to save your project and then click OK
4- Select the Application setting and shoot the Precompiled header and then clich on Finish. 
5- Click on the right of your mouse on the source file  → Add new element →  specify the name of our file, for example "Test.cpp" then click on Add
6- Type the following code on your Test.cpp File:

 #include "stdafx.h"
 #include <highgui.h>
 
int _tmain(int argc, _TCHAR* argv[])

 {
     int c;

     // allocate memory for an image

     IplImage *img;

     // capture from video device #1

     CvCapture* capture = cvCaptureFromCAM(1);

     // create a window to display the images

     cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);

     // position the window

     cvMoveWindow("mainWin", 5, 5);

     while(1)

     {

         // retrieve the captured frame

         img=cvQueryFrame(capture);

         // show the image in the window

         cvShowImage("mainWin", img );

         // wait 10 ms for a key to be pressed

         c=cvWaitKey(10);

         // escape key terminates program

         if(c == 27)

         break;

     }

  return 0;

 }

Aucun commentaire:

Enregistrer un commentaire