Saturday, July 23, 2011

OpenCV for Visual C++ 2010 Express Edition

This is how it is done.

  1. If you do not have Visual C++ 2010 Express Edition, get it from http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
  2. Get OpenCV from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/ 
  3. Choose OpenCV-2.2.0-win32-vs2010.exe
  4. Install it following the easy instructions. (add the OpenCV path to the PATH variable when asked)
next let us see how Visual C++ 2010 Express Edition can be configured. This can be easily done using a project property sheet.
  1. First go to View in VC++ Express Edition and check whether the Property Manger is there. If not, go to Tools->Settings and choose Expert Settings.
  2. Next, choose Property Manager from View; this will open up Property Manager side-by-side with solution explorer and Class view.
  3. Right click on top of your project name and since this is first time, click "Add New Project Property Sheet" and give a suitable name for your property sheet.
  4. By double clicking on the file name open the newly created property file.
  5. In Common Properties->C++->General: Additional Include Directories enter
    1. <OpenCV2.2 directory>\include;
  6. In Linker->General: Additional LibraryDirectories enter
    1. <OpenCV2.2 directory>\lib
  7. In Input: Additional Dependencies enter
    1. opencv_core220d.lib;opencv_highgui220d.lib;opencv_video220d.lib;opencv_ml220d.lib;opencv_legacy220d.lib;opencv_imgproc220d.lib if you are in debug mode
    2. opencv_core220.lib;opencv_highgui220.lib;opencv_video220.lib;opencv_ml220.lib;opencv_legacy220.lib;opencv_imgproc220.lib if you are release mode
now test the installation using this example code. Change the image file name.

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