Pre Requirements:
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\vc11\bin
For x64
;C:\opencv\build\x64\vc11\bin
- Save it.
- Restart Windows
Add property page
- Start new C++ console project in Visual Studio 2012
- View --> Property Manager (Property Manager will appear to side plane)
- Right click Debug --> Add New Project Property Sheet
- Name the property sheet, OpenCV.props
- Select tab, C++ --> General
- Add the following line to Additional Include Directories
- Select tab, Linker --> General
- Add the following line to Additional Library Directories
C:\opencv\build\x86\vc11\lib
For x64
C:\opencv\build\x64\vc11\lib
- Select tab, Linker --> Input
- Add the following lines to Additional Dependancies
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_nonfree246d.lib
opencv_flann246d.lib - Click OK
- You have finished configuring. Test OpenCV
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
Mat img = imread("C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg");
imshow("Display",img);
waitKey();
return 0;
}
Reuse the Property Sheet
- Go to the project location in Windows Explorer.
- You will find a OpenCV.props file.
- Back up the file.
- Start new C++ console project in Visual Studio 2012
- View --> Property Manager (Property Manager will appear to side plane)
- Right click Debug --> Add Existing Project Property Sheet
- Locate your backed up OpenCV.props file.
- Now all OpenCV configurations are added to the project.
- Test with the above code.
No comments:
Post a Comment