Improtant: If you are building a x86 application (even though windows platform of the programming machine is x64), you must use "For x86" sections of the article. You can find or change the application platform from Build -> Configuration Manager -> Active Solution Platform after you create the project.
- Download the latest OpenCV version from http://opencv.org/downloads.html
- Extract it. ( C:\opencv )
- Start -> Right click My Computer -> Properties -> Advanced System Settings -> Environment Variables
- Select Path in System Variables. Add the following line.
For x86
;C:\opencv\build\x86\vc10\bin
;C:\opencv\build\common\tbb\ia32\vc10
(Only if the folder exists)
For x64
;C:\opencv\build\x64\vc10\bin
;C:\opencv\build\common\tbb\intel64\vc10
(Only if the folder exists)
- Save
it.
- Restart
Windows
- Start
new c++ console project in Visual Studio 2010
- Project
-> Properties
- Select C++
-> General tab
- Add
the following lines to Additional
Include Directories
C:\opencv\build\include\
C:\opencv\build\include\opencv
- Select Linker
-> General
- Add
the following lines to Additional
Library Directories
For x86
C:\opencv\build\x86\vc10\lib
For x64
C:\opencv\build\x64\vc10\lib
C:\opencv\build\x86\vc10\lib
For x64
C:\opencv\build\x64\vc10\lib
- Select Linker
-> Input
- Add
the following to Additional
Dependencies in Debug Configurations.
(245 is for opencv version 2.4.5. Change it appropreately for opencv
version)
opencv_core245d.lib
opencv_imgproc245d.lib
opencv_highgui245d.lib
opencv_ml245d.lib
opencv_video245d.lib
opencv_features2d245d.lib
opencv_calib3d245d.lib
opencv_objdetect245d.lib
opencv_contrib245d.lib
opencv_legacy245d.lib
opencv_nonfree245d.lib
opencv_flann245d.lib
- Add
the following to Additional
Dependencies in Release
Configuration,
if you want to build a release version. (Not required)
opencv_core245d.lib
opencv_imgproc245.lib
opencv_highgui245.lib
opencv_ml245.lib
opencv_video245.lib
opencv_features2d245.lib
opencv_calib3d245.lib
opencv_objdetect245.lib
opencv_contrib245.lib
opencv_legacy245.lib
opencv_nonfree245.lib
opencv_flann245.lib
- Opencv
is ready to use. Try the following example
#include
"stdafx.h"
#include
"opencv2\core\core.hpp"
#include
"opencv2\imgproc\imgproc.hpp"
#include
"opencv2\highgui\highgui.hpp"
using namespace cv;
int _tmain(int argc,
_TCHAR* argv[])
{
VideoCapture
cap(0);
do{
Mat img;
cap >>
img;
imshow("Disp",img);
}while(waitKey(30)<0);
return 0;
}