Download OpenCV 2.2 from SourceForge.
Download VisualC++ Express if you do not have an IDE
1. Create your new project for C++ , empty console application
2. Go to Tools > Option
3. Go to VC++ Directories
4. Add 2 new Include Directories (it's the path where you installed OpenCV, include folder):
- C:\OpenCV2.2\include
- C:\OpenCV2.2\include\opencv
5. Add 1 new Library Directory (it's the path where you installed OpenCV, lib folder):
- C:\OpenCV2.2\lib
6. Go to Linker in the left menu and select Input option
7. Add these entries on Additional Dependencies option:
"C:\OpenCV2.2\lib\opencv_core220d.lib"
"C:\OpenCV2.2\lib\opencv_highgui220d.lib"
"C:\OpenCV2.2\lib\opencv_video220d.lib"
"C:\OpenCV2.2\lib\opencv_ml220d.lib"
"C:\OpenCV2.2\lib\opencv_legacy220d.lib"
"C:\OpenCV2.2\lib\opencv_imgproc220d.lib"
A sample hello world program :
#include "highgui.h"
int main ( int argc, char **argv )
{
cvNamedWindow( "My Window", 1 );
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
CvFont font;
double hScale = 1.0;
double vScale = 1.0;
int lineWidth = 1;
cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
hScale, vScale, 0, lineWidth );
cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return 0;
}
Run the program and you should see the above screen.
For OpenCV 2.3.1
The steps are similar.
However the path varies depending on which build version you would want to use.
I am sticking with Win32 and VS2010
Some updates to the path:
5. Add 1 new Library Directory (it's the path where you installed OpenCV, lib folder):
- C:\OpenCV2.3\build\x86\vc10\lib
6. Go to Linker in the left menu and select Input option
7. Add these entries on Additional Dependencies option
C:\OpenCV2.3\build\x86\vc10\lib\opencv_core231d.lib
C:\OpenCV2.3\build\x86\vc10\lib\opencv_highgui231d.lib
C:\OpenCV2.3\build\x86\vc10\lib\opencv_video231d.lib
C:\OpenCV2.3\build\x86\vc10\lib\opencv_ml231d.lib
C:\OpenCV2.3\build\x86\vc10\lib\opencv_legacy231d.lib
C:\OpenCV2.3\build\x86\vc10\lib\opencv_imgproc231d.lib