Beruflich Dokumente
Kultur Dokumente
3
First, get OpenCV 2.4.3 from sourceforge.net. Its a self-extracting so just double click to start the
installation. Install it in a directory, say C:\.
Wait until all files get extracted. It will create a new directory C:\opencv which contains OpenCV
header files, libraries, code samples, etc.
Now you need to add the directory C:\opencv\build\x86\vc10\bin to your system PATH.
This directory contains OpenCV DLLs required for running your code.
Open Control Panel → System → Advanced system settings → Advanced Tab
→ Environment variables...
On the System Variables section, select Path (1), Edit (2), and
typeC:\opencv\build\x86\vc10\bin; (3), then click Ok.
On some computers, you may need to restart your computer for the system to recognize the
environment path variables.
Make sure that "Debug" is selected in the solution configuration combobox. Right-
click cvtest and select Properties → VC++ Directories.
Select Include Directories to add a new entry and type C:\opencv\build\include.
opencv_core243d.lib
opencv_imgproc243d.lib
...
You've done setting up Visual C++, now is the time to write the real code. Right click your project
and select Add → New Item... → Visual C++ → C++ File.
Name your file (e.g: loadimg.cpp) and click Ok. Type the code below in the editor:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main()
{
Mat im = imread("c:/full/path/to/lena.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
The code above will load c:\full\path\to\lena.jpg and display the image. You can use any
image you like, just make sure the path to the image is correct.
Type F5 to compile the code, and it will display the image in a nice window.
And that is your first OpenCV program!