OpenCV-2.1.0 using CMake and Visual C++ 2010 Express on Windows XP SP3 32-bit
This tutorial will walk the user through creation of the OpenCV libraries using two versions of CMake as well as Visual C++ 2010 Express. There is a small helloworld example at the end.
This document was based off of OpenCV 2.1.0 with Visual Studio 2008.
Pre-Requisites
Installation of the pre-requisites is beyond the scope of this tutorial. Save for VisualC++ which required SP3 and a .NET upgrade, the installs are relatively straightforward.
Note: Why are two versions of CMake involved? Because 2.8.2 threw errors, and 2.6.4 didn't have the ability to target MSVC 2010E. 2.6.4 automatically puts libraries(?) somewhere that are usable by 2.8.2. *Anyone with deeper knowledge on extending 2.6.4 to target MSVC 2010E, or who knows how to directly solve the build issues with 2.8.2, please feel free to update...*
- 'Add CMake to the system PATH for current user' *radio*
- 'Add CMake to the system PATH for current user' *radio*
CMake OpenCV 2.1.0
Download OpenCV-2.1.0-win.zip
- Extract to 'C:\Program Files\'
- Create new folder: 'C:\Program Files\OpenCV-2.1.0\build'
Start -> Programs -> CMake 2.8 -> CMake (cmake-gui).
- Where is the source code: 'C:/Program Files/OpenCV-2.1.0/' (or for newer versions: 'C:\OpenCV2.2')
- Where to build the binaries: 'C:/Program Files/OpenCV-2.1.0/build'(or for newer versions: 'C:\OpenCV2.2\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.
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;'
Make the content of 'OpenCV_Helloworld.cpp' as such:
// OpenCV_Helloworld.cpp : Defines the entry point for the console application.
// Created for build/install tutorial, Microsoft Visual C++ 2010 Express and OpenCV 2.1.0
#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");
cvNamedWindow("Image:",1);
cvShowImage("image:",img);
cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}Debug -> Build Solution
Copy image to 'C:\Documents and Settings\windowsxp\My Documents\Visual Studio 2010\Projects\OpenCV_Helloworld\OpenCV_Helloworld'. Or to wherever you saved the project to...
Debug -> Start Debugging
- Done.