1. Download OpenCV 2.2.0
Address: http://sourceforge.net/projects/opencvlibrary/
2. Install
Run OpenCV-2.2.0-win32-vs2010.exe
3. Set OpenCV envirnment
After a new project, select Project -> XXX Properties -> Configuration Properties -> VC++ Directories
In Inculde Directories
In Library Directories
Select Configuration Properties -> Linker -> Input
In Additional Dependencies
4. Create a Win32 Console Application
Code:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
// Load an image from disk into Main Memory (BMP, DIB, JPEG, JPE, PNG, PBM, PGM, PPM, SR, RAS and TIFF)
IplImage *image = cvLoadImage("Your Image File Path");
// Create a window (title, 0/CV_WINDOW_AUTOSIZE)
cvNamedWindow("ImageShow", CV_WINDOW_AUTOSIZE);
// Show a image in a window (window title, image)
cvShowImage("ImageShow", image);
// Wait for an event (<= 0: Keyboard event, > 0: wait for n msecs)
cvWaitKey(0);
// Release image from Main Memory (image = NULL)
cvReleaseImage(&image);
// Release window from Main Memory
cvDestroyWindow("ImageShow");
return 0;
}
Note:
1) IplImage * cvLoadImage(const char * fileName, int flags = CV_LOAD_IMAGE_COLOR)
fileName: Image file name/path,
flags: Define image COLOR and DEEPTH
2) void cvShowImage(const char * name, const CvArr * image)
name: Window name,
image: image will be shown
3) int cvWaitKey(int delay = 0)
delay: time to delay (delay <= 0, wait Keyboard event forever, dealy > 0, wait "delay" ms)