I ran into some difficulties: the documentation is a bit outdated.
This solution is based on this tutorial: http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010_CMake
Here are the exact steps I took to get the opensv 2.4.2 hello world example working with Visual C ++ 2010 Express:
Take the source code
Download opencv.
Extract opencv to C: \
Binary creation
Download cmake. Open cmake gui ..
Where is the source code: C: / opencv
Where to build binary files: C: / opencv / build
Click "Customize" - for the generator, select Visual Studio 10 Click "Create".
In C: \ opencv \ build you should see OpenCV.sln.
Open the solution file using VS C ++ Express and create it.
Setting up the hello world project
Create a new project in VS. Select a console application and check the boxes with precompiled headers. Right-click the solution file and select properties.
In the VC ++ Directories window, add the following:
Include directories: C: \ opencv \ build \ include; C: \ opencv \ build \ include \ opencv; C: \ opencv \ build \ include \ opencv2
Library Directories: C: \ OpenCV \ Build \ Lib \ Debug
Sources: C: \ OpenCV \ build \ enable
In C ++ β Linker β Input add the following additional dependencies:
opencv_core242d.lib opencv_highgui242d.lib
Hello World Content
Modify the content as suggested in the tutorial to:
#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; }
Place the image (or any image) in the project directory.
Now create and delete Debug, and it should work. Hope this helps someone.