OpenCV-2.1.0 using CMake and Visual C++ 2010

Test on Windows7 SP1 32-bit

CMake OpenCV 2.1.0 

  1. Download
  2. Extract to 'C:\Program Files\'
  3. Create new folder: 'C:\Program Files\OpenCV-2.1.0\build'
  4. Start -> Programs -> CMake 2.8 -> CMake (cmake-gui).
    • Where is the source code: 'C:/Program Files/OpenCV-2.1.0/'
    • Where to build the binaries: 'C:/Program Files/OpenCV-2.1.0/build'  
  • 'Configure'
  • Specify the generator for this project: 'Visual Studio 10'
  • Use default native compilers: 'radio'
  • 'Configure'
  • 'Generate'   

Build OpenCV 2.1.0

  • Start -> Programs -> Microsoft Visual Studio 2010 Express -> Microsoft Visual C++ 2010 Express
    • File -> Open -> Project/Solution...'C:\Program Files\OpenCV-2.1.0\build\OpenCV.sln'
    • After MSVC has finished parsing all of the files (It will say 'Ready' in the bottom left corner): Debug -> Build Solution

  After some time, OpenCV should build successfully.
OpenCV 2.1.0 HelloWorld

  • To permanantly include necessary .dll files, add 'C:\Program Files\OpenCV-2.1.0\build\bin\Debug' to PATH by visiting Advanced tab in System of Windows. (add to system path manually)
  • Start -> Programs -> Microsoft Visual Studio 2010 Express -> Microsoft Visual C++ 2010 Express
    • File -> New -> Project
    • Name: 'OpenCV_Helloworld'...'OK'...'Finish' 

 Configure Project Directories 

  • Project -> OpenCV_Helloworld Properties...Configuration Properties -> VC++ Directories
  • Include Directories...add: 'C:\Program Files\OpenCV-2.1.0\include\opencv;'
  • Library Directories...add: 'C:\Program Files\OpenCV-2.1.0\build\lib\Debug;'
  • Source Directories...add: 'C:\Program Files\OpenCV-2.1.0\src\cv;C:\Program Files\OpenCV-2.1.0\src\cvaux;C:\Program Files\OpenCV-2.1.0\src\cxcore;C:\Program Files\OpenCV-2.1.0\src\highgui;C:\Program Files\OpenCV-2.1.0\src\ml;'
  • Linker -> Input -> Additional Dependencies...add: 'cv210d.lib;cxcore210d.lib;highgui210d.lib;

#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
IplImage *img = cvLoadImage("funny-pictures-cat-goes-pew.jpg");


return 0; 
ที่มา: OpenCV-2.1.0 using CMake and Visual C++ 2010 Express on Windows XP SP3 32-bit
ปล. ติดตั้งจาก OpenCV-2.1.0-win32-vs2008.exe (ไม่ได้ใช้ CMake) แล้วกำหนดค่า Proproties ของ Project ตามข้างบนแล้ว แต่เวลา run แล้วเกิด Error ดังนี้ "The application was unable to start correctly (0xc0150002)" ทางแก้คือ เปลี่ยนจาก 'cv210d.lib;cxcore210d.lib;highgui210d.lib;'  เป็น 'cv210.lib;cxcore210.lib;highgui210.lib;