Wednesday, January 20, 2010

Using CMake to configure OpenCV 2.0 for use with Visual Studio 2008

I use CMake 2.8.0 to configure OpenCV 2.0 so that I could build the library files needed to develop software using Visual Studio (C++) 2008 Professional Edition.
CMake can be downloaded from http://www.cmake.org/cmake/resources/software.html .
After having CMake installedin your computer, I did the following steps:
  1. Run CMake (cmake-gui).
  2. Enter C:/OpenCV2.0 as the source code folder.
  3. Enter C:/OpenCV2.0/vs2008 as the folder where I want to build the binaries.
  4. Click Configure.
  5. Choose Visual Studio 9 2008, and choose Use default native compilers. Click Finish.
  6. Click Generate. It will generate the required files in C:/OpenCV2.0/vs2008
  7. Open the file OpenCV.sln in the folder C:\OpenCV2.0\vs2008 with Visual Studio 2008.
  8. Choose menu Build, Configuration Manager. Choose Active solution configuration: Debug.
  9. Choose menu Build, Build solution. Wait for a while until it finished.
  10. Verify that the following library files are created and located in C:\OpenCV2.0\vs2008\lib\Debug :
    • cv.lib
    • cv200d.lib
    • cvaux200d.lib
    • cvhaartraining.lib
    • cxcore200d.lib
    • cxts200d.lib
    • highgui200d.lib
    • ml200d.lib
    • opencv_ffmpeg200d.lib
  11. Choose menu Build, Configuration Manager. Choose Active solution configuration: Release.
  12. Choose menu Build, Build solution. Wait for a while until it finished.
  13. Verify that the following library files are created and located in C:\OpenCV2.0\vs2008\lib\Release :
    • cv.lib
    • cv200.lib
    • cvaux200.lib
    • cvhaartraining.lib
    • cxcore200.lib
    • cxts200.lib
    • highgui200.lib
    • ml200.lib
    • opencv_ffmpeg200.lib
  14. Now we have had the needed library files for building computer vision application with OpenCV 2.0 and Visual C++ 2008.

OpenCV 2.0 Installation

To install OpenCV 2.0 for Windows:
  • Download OpenCV2.0 for Windows from http://sourceforge.net/projects/opencvlibrary/ . Choose the file named OpenCV-2.0.0a-win32.exe.
  • Install it to the default directory, which is C:\OpenCV2.0
The following screenshots will be displayed when installing OpenCV 2.0 for Windows:










This guide assumes that you already had Microsoft Visual C++ 2008 Professional Edition installed in your computer.

Unlike in the OpenCV 1.0, the installation package of OpenCv 2.0 does not include pre-compiled OpenCV libraries for Visual Studio (Visual C++).
Therefore, after completing the installation of OpenCV 2.0 you need to build the libraries by yourself before using them with Visual C++. You will need CMake to configure OpenCV before you build the libraries using Visual C++ 2008.
CMake can be downloaded from http://www.cmake.org/cmake/resources/software.html and then it should be installed in your computer.
When this guide was written, I used CMake 2.8.0.

After successfully built OpenCV libraries, I got these files that I can use with Visual Studio (C++) 2008 Professional Edition:
In the folder C:\OpenCV2.0\vs2008\lib\Debug:
  • cv.lib
  • cv200d.lib
  • cvaux200d.lib
  • cvhaartraining.lib
  • cxcore200d.lib
  • cxts200d.lib
  • highgui200d.lib
  • ml200d.lib
  • opencv_ffmpeg200d.lib
In the folder C:\OpenCV2.0\vs2008\lib\Release:
  • cv.lib
  • cv200.lib
  • cvaux200.lib
  • cvhaartraining.lib
  • cxcore200.lib
  • cxts200.lib
  • highgui200.lib
  • ml200.lib
  • opencv_ffmpeg200.lib
However, for some unknown reason, the library files in C:\OpenCV2.0\vs2008\lib\Debug do not seem to work properly. When I use them, the application build in Visual C++ could be compiled without errors, but failed to run properly. It always shows the message:
"The application failed to initialize properly (0xc0150002). Click OK to terminate the application."

The library files in C:\OpenCV2.0\vs2008\lib\Release work well though. So I always choose to use the library files in the Release folder instead.

Introduction to OpenCV

For introduction to OpenCV, please read the following resources:
  • http://opencv.willowgarage.com/
  • http://en.wikipedia.org/wiki/OpenCV
  • http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
This web site is intended to show the examples, step-by-step guide, and practical uses of OpenCV for developing programs with Visual C++ (Visual Studio) 2008 Professional Edition.

I use Visual C++ 2008 Professional Edition to develop the examples in this web site. If you use the other compiler or different version of Visual C++, please be aware that it might work differently.