Monday, May 9, 2011

OpenCV with Eclipse CDT and MinGW

Prerequisites:
  1. CMake  http://www.cmake.org/ 
  2. MinGW with MSYS http://www.mingw.org/ 
  3. OpenCV source code http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/ 
  4. Eclipse CDT http://www.eclipse.org/cdt/
 Let say, you download OpenCV and put it into C:/c-dev/OpenCV-2.2.0
  1. Open MSYS and go to OpenCV folder
    cd C:/c-dev/OpenCV-2.2.0
  2. Run CMake command to generate "Build files"
    cmake -G "Unix Makefiles" .
  3.  Build OpenCV
    make
    make install
  4. Add bin directory to your PATH
    C:\c-dev\OpenCV-2.2.0\bin
After successfully build process you can see dll files in "bin" folder and library files ".dll.a" in "lib" folder. Now you are ready to make the first OpenCV program.
  • Create new project

  • Add header path

  • Add library path

  • Add libraries


Time to code

#include <iostream>
#include "opencv2/opencv.hpp"

int main(int argc, char** argv) {
cout << "Hello OpenCV" << endl;
IplImage* img = cvLoadImage("lena.jpg", CV_LOAD_IMAGE_COLOR);
if (img) {
cvShowImage("Hello OpenCV", img);
cvWaitKey(0);
cvDestroyAllWindows();
}
return 0;
}

No comments:

Post a Comment