OpenCV-2.1.0 using CMake and Visual C++ 2010

Test on Windows7 SP1 32-bit

Pre-Requisites

ขั้นตอนการคอมไพล์ OpenCV-2.1.0 ด้วย CMake และ Visual C++ 2010

  1. เตรียม Solution ของ OpenCV 2.1.0 ด้วย CMake
  2. Build OpenCV 2.1.0 Solution ด้วย Visual C++ 2010
  3. สร้างโปรเจ็กส์ HelloWorld บน Visual C++ 2010
    • Configure Project Directories

เตรียม Solution ของ OpenCV 2.1.0 ด้วย CMake

  1. Download OpenCV-2.1.0-win.zip
  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/buildopencv_cmake01
  5. Click ‘Configure‘ button
    • Specify the generator for this project: Visual Studio 10
    • select Use default native compilers
      opencv_cmake02
  6. Click ‘Configure‘ buttonopencv_cmake03opencv_cmake04
  7. Click ‘Generate‘ buttonopencv_cmake05

Build OpenCV 2.1.0 Solution

Start -> Programs -> Microsoft Visual Studio 2010  -> Microsoft Visual C++ 2010

  • File -> Open -> Project/Solution…’C:\Program Files\OpenCV-2.1.0\build\OpenCV.slnopencv_cmake06
  • After MSVC has finished parsing all of the files (It will say ‘Ready‘ in the bottom left corner): Build -> Build Solutionopencv_cmake07opencv_cmake08
  • After some time, OpenCV should build successfully.opencv_cmake09

สร้างโปรเจ็กส์ 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)
    opencv_cmake10
  • Start -> Programs -> Microsoft Visual Studio 2010 -> Microsoft Visual C++ 2010
    • File -> New -> Project
    • Name: ‘OpenCV_Helloworld‘…’OK’…’Finish’
      opencv_cmake11

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;’
    opencv_cmake12
  • Linker -> Input -> Additional Dependencies…add: ‘cv210d.lib;cxcore210d.lib;highgui210d.lib;
    opencv_cmake13
  • copy image test to project directory
    opencv_cmake14

ที่มา: 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;‘ http://opencv-users.1802565.n2.nabble.com/Application-failed-to-start-correctly-0xc0150002-td4107823.html

Using OpenCV-2.1.0 with MS Visual C++ 2010 on Windows 7

ที่มา: Using OpenCV-2.1.0 with MS Visual C++ 2010 on Windows 7

 

หลังจากติดตั้งเสร็จ พอรัน helloworld เจอ error ดังนี้

The application was unable to start correctly (0*0150002). Click Ok to close the application.

วิธีแก้

ไปที่ Project -> Proporties -> Linker-> Input -> Additional Dependencies

จากนั้นเปลี่ยนจาก cv210d.lib; cvaux210d.lib; cxcore210d.lib; highgui210d.lib; ml210d.lib;

เป็น cv210.lib; cvaux210.lib; cxcore210.lib; highgui210.lib; ml210.lib; opencv_ffmpeg210.lib;

ก็จะไม่ error อีก

 

นอกจาก error แล้ว ยังมีคำเตือนคำเตือนเหล่านี้อีก

‘C:\Windows\SysWOW64\ntdll.dll’, Cannot find or open the PDB file
‘C:\Windows\SysWOW64\kernel32.dll’, Cannot find or open the PDB file
‘C:\Windows\SysWOW64\kernellbase.dll’, Cannot find or open the PDB file

วิธีแก้

Go to Tools->Options->Debugging->Symbols and select checkbox “Microsoft Symbol Servers”

http://stackoverflow.com/questions/4813975/why-is-visual-studio-2010-not-able-to-find-open-pdb-files

แต่หลังจากแก้ไข้แล้ว เจอ คำเตือนอันใหม่ดังนี้

‘OpenCV_helloworld.exe’: Loaded ‘C:\OpenCV2.2\bin\opencv_imgproc220d.dll’, Cannot find or open the PDB file
‘OpenCV_helloworld.exe’: Loaded ‘C:\WINDOWS\system32\imm32.dll’, Symbols loaded (source information stripped).

ยังไม่รู้ว่าแก้ยังไง