Install opencv 2.4.9 in vs 2012
2.1 prepare the environment
- Install Visual Studio 2012
- Download the latest opencv version.
2.2 install opencv2.2.1. double-click the downloaded OpenCV-2.x.x.exe. Select the location where you want to decompress it.
2.2.2. Set environment variables.
Step 1: Open the environment variable settings page.
Method 1: Start-> Control Panel-> system and security-> system-> advanced system settings-> advanced-> Environment Variables
Method 2: Start-> control panel, search for "environment variables" in the upper right corner, and click "edit system environment variables"-> Environment Variables
After the preceding operations, you can see the following interface:
Add *** \ opencv \ build \ x86 \ vc11 \ Lib *** to the system variable to indicate which drive letter is used.
* ** \ Opencv \ build \ x86 \ vc11 \ bin ** indicates which drive letter
Click "OK" (restart or logout is required ). 2.3.3. Set project properties.
2.3.3.1 Step 1: Create a property sheet.
On the far left side of Vs, find the "Property Manager" tab, as shown in. (If "Property Manager" is not found ". click View> property manager on the menu bar)
As shown in, right-click "Debug | Win32" and click "Add new project property sheet"
Enter the following content.
Name, as long as you know
Location, as long as you can find it.
Click "add" to complete the creation.
2.3.3.2 Step 2: edit the property sheet attribute
As shown in, edit the "opencv244" attribute.
Make the following edits:
Add "{opencv} \ build \ include" to include directories ".
Add "{opencv} \ build \ x86 \ vc11 \ Lib" to library directories. (replace {opencv} with your opencv installation path)
As shown in the figure, click "linker-> input-> additional dependencies ".
Add the following content:
Opencv_core249d.lib
Opencv_imgproc249d.lib
Opencv_highgui249d.lib
Opencv_ml249d.lib
Opencv_video249d.lib
Opencv_features2d249d.lib
Opencv_calib3d249d.lib
Opencv_objdetect249d.lib
Opencv_contrib249d.lib
Opencv_legacy249d.lib
Opencv_flann249d.lib
Replace "249" with the downloaded opencv version. For example, if your version is 2.4.6, replace all 249 with 246.
Complete settings
2.3.3.4. Set the release attribute
After setting project properties, your debug version can be used properly. If you need to set the release version, repeat Step 3 above.
There are two differences in the middle:
1. In Step 2.3.3.1, you need to add property sheet to "Release | Win32.
2. In Step 2.3.3.2, all additional dependencies and xxx249d. Lib are removed from "D". For example, "opencv_core249d.lib" is changed to "opencv_core249.lib". All items are removed and changed:
Opencv_core249.lib
Opencv_imgproc249.lib
Opencv_highgui249.lib
Opencv_ml249.lib
Opencv_video249.lib
Opencv_features2d249.lib
Opencv_calib3d249.lib
Opencv_objdetect249.lib
Opencv_contrib249.lib
Opencv_legacy249.lib
Opencv_flann249.lib
2.3.4 compile and run the test code.
2.3.4.1. Create main. cpp. Enter the following code
#include <opencv2/opencv.hpp>using namespace cv;int main(){Mat img=imread("../img.png");if(img.empty()){fprintf(stderr,"Error: load image failed.");return -1;}namedWindow("image",CV_WINDOW_AUTOSIZE);imshow("image",img);waitKey();return 0;}
2.3.4.2 put an image in your project directory and name it img.png:
Final result: