Abstract: Using Opencv in the VS2010 environment, many configuration methods have been found on the internet, but most of them are old versions. Many new users cannot start with the latest version of Opencv, I wrote such a detailed Configuration Guide for New Kids shoes and pasted it for sharing. Note that the Opencv library used in this configuration method is the built-in dll library that is directly installed with Opencv, and you cannot debug Opencv in your. If you need to debug Opencv, you must apply the self-compiled Opencv library and compile your own Opencv library. There are many examples on the Internet.
1. Download Software
Download the OpenCV-2.4.0 and double-click to decompress it to % opencv % (replace the full name of your own opencv path where % opencv % appears, such as D: \ program \ opencv ).
Download and install VS2010.
2. Configure OpenCV Environment Variables
Computer> (right-click) Properties> advanced system Settings> advanced (Label)> environment variable> (double-click) path (user, choose one of the paths in the System) -> Add "% opencv % \ build \ x86 \ vc10 \ bin" and "% opencv % \ build \ common \ tbb \ ia32 \ vc10" to the variable value (% in it) opencv % remember to change to your own opencv path. For example, my: D: \ program \ ifly \ bin; D: \ Program Files (x86) \ opencv \ build \ x86 \ vc10 \ bin; D: \ Program Files (x86) \ opencv \ build \ common \ tbb \ ia32 \ vc10 ).
3. Configure the opencv dependency of the project. (You must reconfigure each time you create a new project. To perform this step, go to step 1 to create a project)
1) project (menu item)->... Property-> VC ++ Directory: You need to configure "include directory" and "library directory.
2) configure the "include directory" item: Add line "% opencv % \ build \ include.
However, when running someone else's opencv project, someone else may directly reference the subdirectory path of the preceding directory. If the include error occurs, then add "% opencv % \ build \ include \ opencv" and "% opencv % \ build \ include \ opencv2" to solve the problem.
3) configure the "library directory" item: Add row "% opencv % \ build \ x86 \ vc10 \ lib.
4) configure the connector: Project (menu item)->... Property> connector> input> additional dependency
Add the following libraries for debug Configuration:
Opencv_calib3d240d.lib
Opencv_contrib240d.lib
Opencv_core240d.lib
Opencv_features2d240d.lib
Opencv_flann240d.lib
Opencv_gpu240d.lib
Opencv_highgui240d.lib
Opencv_imgproc240d.lib
Opencv_legacy240d.lib
Opencv_ml240d.lib
Opencv_objdetect240d.lib
Opencv_ts240d.lib
Opencv_video240d.lib
If it is a release configuration (later, you only need to add the above debug configuration), then add:
Opencv_calib3d240.lib
Opencv_contrib240.lib
Opencv_core240.lib
Opencv_features2d240.lib
Opencv_flann240.lib
Opencv_gpu240.lib
Opencv_highgui240.lib
Opencv_imgproc240.lib
Opencv_legacy240.lib
Opencv_ml240.lib
Opencv_objdetect240.lib
Opencv_ts240.lib
Opencv_video240.lib
4. Create a console project test with VS2010:
1) file-> New-> Project-> Visual C ++-> Win32 console application (enter the name test)
2) choose "OK"> "Next"> select "Empty Project" as the additional option. Click "OK"> "complete ".
3) Solution Explorer-> source file (right-click)-> Add-> new item
4). Visual C ++-> C ++ file: Enter the name test to add
5) paste the following code and save it.
1 # include <opencv2 \ opencv. hpp> 2 # include <iostream> 3 # include <string> 4 using namespace cv; 5 using namespace std; 6 int main () 7 {8 Mat img = imread ("pp.jpg"); 9 if (img. empty () 10 {11 cout <"error"; 12 return-1; 13} 14 imshow ("xx photo", img); 15 waitKey (); 16 17 return 0; 18}
6. Change the profile to pp.jpg and put it in the test folder of the project (the test folder in it)
7) configure the opencv dependencies of the project according to the 3rd step.
8) Press F5. If your image is displayed, it will be OK.
This article is transferred from: http://www.cnblogs.com/freedomshe/archive/2012/04/25/2470540.html