Tuesday, January 8, 2013

OpenCV 2.4.3 with Visual Studio 2012

OpenCV is a well known library that allows programmers to easily do Image Processing. Following configurations works for 32-bit Visual Studio Version. It may work for 64-bit too. But I don't have a 64-bit version of Visual Studio. :)

I don't know much about what each process does. I have gone through several web sites and summarized the correct version,
  1. Download OpenCV 2.4.3
  2. Then extract it to any path you want. 
      • Let the path be C:\OpenCV
  3. Add following two environment variables under 'PATH'.
      • User variables: ;C:\OpenCV\opencv\build\x86\vc10\bin
      • System variables: ;C:\OpenCV\opencv\build\x86\vc10\bin
  4. Open Microsoft Visual Studio 2012.
  5. Start a new win32 console program.
  6. View >> Other Windows >> Property Manager.

  7. Double click on the 'Debug | win32'.
  8. Common Properties >> C/C++ >> General

  9. Add the following under the additional include directories,
      • C:\OpenCV\opencv\build\include;
  10. Common Properties >> Linker >> General

  11. Add the following under Additional Library Directories,
      • C:\OpenCV\opencv\build\x86\vc10\lib;
  12. Common Properties >> Linker  >> Input

  13. Add the following under Additional Dependencies,
      • opencv_core243d.lib;
      • opencv_imgproc243d.lib;
      • opencv_highgui243d.lib;
      • opencv_ml243d.lib;
      • opencv_video243d.lib;
      • opencv_features2d243d.lib;
      • opencv_calib3d243d.lib;
      • opencv_objdetect243d.lib;
      • opencv_contrib243d.lib;
      • opencv_legacy243d.lib;
      • opencv_flann243d.lib;
  14. Now click ok.
  15. Next I have downloaded two '.dll's which were missing,
    http://www.mediafire.com/?115pz9e0xpa0059
    Then I extracted them into,
    C:\OpenCV\opencv\build\x86\vc10\bin
  16. Finally run the following sample program to make sure that your configuration is successful.
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
/**
* @function main
*/
int main( int argc, const char** argv )
{
CvCapture* capture;
IplImage* frame = 0;
while (true)
{
//Read the video stream
capture = cvCaptureFromCAM(1);
frame = cvQueryFrame( capture );
// create a window to display detected faces
cvNamedWindow("Sample Program", CV_WINDOW_AUTOSIZE);
// display face detections
cvShowImage("Sample Program", frame);
int c = cvWaitKey(10);
if( (char)c == 27 ) { exit(0); }
}
// clean up and release resources
cvReleaseImage(&frame);
return 0;
}
Enjoy!!!

Reference:

  1. http://docs.opencv.org/opencv_tutorials.pdf
  2. http://karanjthakkar.wordpress.com/2012/11/21/usin-opencv-2-4-2-with-visual-studio-2012-on-windows-7-64-bit/

No comments:

Post a Comment