1. Download OpenCV-2.4.7 from opencv.org,unzip to a directory.
For example, the directory is ”C:\opencv”and there are two sub-folders under it : “build” and “sources”.
2. Configure environment variable
Computer->Properties->Advanced System settings->Environment Variables->System (or user)variables->Path->Variable value:
add“; C:\opencv\build\x86\vc11\bin; C:\opencv\build\x86\vc11\lib” at the end.
3. Create a new Win32 console project for test
Open VS2012,File->New->Project->Win32 Console Application, give a name, select empty project and click finish button.
4. Configure OpenCV dependencies
1) View->Property Manager
Add new Project Property Sheet for both Debug|Win32 and/or Release|Win32. Double click the new Property pages.
2) VC++ Directories->Include Directories,add an item “C:\opencv\build\include;”.
( You can also try to add “C:\opencv\build\include\opencv”and/or “C:\opencv\build\include\opencv2”.)
VC++Directories->Library Directories, add an item “C:\opencv\build\x86\vc11\lib;”
3) Linker->Input->Additional Dependencies, add following items.
For Debug|Win32,
opencv_calib3d247d.lib
opencv_contrib247d.lib
opencv_core247d.lib
opencv_features2d247d.lib
opencv_flann247d.lib
opencv_gpu247d.lib
opencv_highgui247d.lib
opencv_imgproc247d.lib
opencv_legacy247d.lib
opencv_ml247d.lib
opencv_objdetect247d.lib
opencv_ts247d.lib
opencv_video247d.lib
For Release|Win32,
opencv_calib3d247.lib
opencv_contrib247.lib
opencv_core247.lib
opencv_features2d247.lib
opencv_flann247.lib
opencv_gpu247.lib
opencv_highgui247.lib
opencv_imgproc247.lib
opencv_legacy247.lib
opencv_ml247.lib
opencv_objdetect247.lib
opencv_ts247.lib
opencv_video247.lib
Note that in each line, "247" represents the version and "d" means debug. If other version of opencv is used, just change "247" to other number.
5) In VS2012, Solution Explorer->SourceFiles->right click->Add->New Item->C++ File (.CPP).
Copy the source code from “C:\opencv\sources\samples\cpp\opencv_version.cpp”. Run it.
#include "opencv2/core/core.hpp"
#include <iostream>
const char* keys =
{
"{ b |build |false | print complete build info }"
"{ h |help |false | print this help }"
};
int main(int argc, const char* argv[])
{
cv::CommandLineParser parser(argc, argv, keys);
if (parser.get<bool>("help"))
{
parser.printParams();
}
else if (parser.get<bool>("build"))
{
std::cout << cv::getBuildInformation() << std::endl;
}
else
{
std::cout << "OpenCV " << CV_VERSION << std::endl;
}
getchar();
return 0;
}
For the future project, try to add #include <opencv2\opencv.hpp> at the beginning to include all headers for OpenCV. The property sheet can be saved as .props file. Then next time the file can be added to the project.