How to configure opencv in Visual Studio 2010

Time:2020-10-29

When using OpenCV with VS, you don’t want to configure it globally. It’s boring to configure every time.

In view of this, I would like to introduce a simple method.

The premise of configuring the environment is that the appropriate version of OpenCV is successfully installed.

I use opencv2.4.9 here. After decompressing this version, I find a directory called build, which has been compiled.

WeSuppose the build directory structure is as shown in Figure 1

Figure 1. Build directory structure

And suppose that the build folder is in the opencv directory of disk D. if not, you can move it to the opencv directory of disk D.

We want toDevelop with C + +. The platform is x86Of course, the specific platform depends on your actual situation.

Step 1:Create a once and for all project property sheet!

Open Visual Studio 2010 and create a new project, as shown in Figure 2

Figure 2. Creating a WIN32 console application

Click OK, and then go to the interface shown in Figure 3. Select an empty item.

Figure 3. Select an empty item

Click finish.

Select View > property manager from the menu bar, as shown in Figure 4.

Figure 4. Select attribute manager

Then expand the tabs of the property manager, as shown in Figure 5

Figure 5. Expand the property manager

Right click debug| Win32 and select “add new project property table”. The operation steps are shown in figures 6 and 7

Figure 6

Figure 7 adding opencv_ Debug property sheet

The results are shown in Figure 8

Figure 8. Opencv_ Add result to debug property sheet

Double click the newly added property sheet.

Edit the include directory as shown in Figure 9.

Figure 9. Edit the included directory

Figure 10. Add opencv’s include directory

Figure 11. Add additional Library Directory

Figure 12. Adding additional dependencies

In Figure 12, additional dependency suffixes are preceded by a D, which is the only difference from release.

The list of added library file names is as follows (pay attention to your version number, do not copy and paste directly)


opencv_imgproc249d.lib 
opencv_calib3d249d.lib 
opencv_contrib249d.lib 
opencv_core249d.lib 
opencv_features2d249d.lib 
opencv_flann249d.lib 
opencv_gpu249d.lib 
opencv_highgui249d.lib 
opencv_legacy249d.lib 
opencv_ml249d.lib 
opencv_nonfree249d.lib 
opencv_objdetect249d.lib 
opencv_ocl249d.lib 
opencv_photo249d.lib 
opencv_stitching249d.lib 
opencv_superres249d.lib 
opencv_ts249d.lib 
opencv_video249d.lib 
opencv_videostab249d.lib 

Finally, click OK.

Then open it to your project directory, and you will see the file shown in Figure 13

Figure 13 opencv_ Debug property sheet

Copy the red box file in Figure 13 to a suitable directory and keep it. Just add it next time.

Step 2:Create a new project using OpenCV:

1. Create a new empty project demo2, the method will not be described.

2. Switch to the property manager, right-click debug|win32 and select Add existing property sheet~

Figure 14. Adding an existing property sheet

Find your saved OpenCV_ Debug.props The result is shown in Figure 15

Figure 15 add attribute sheet results

At this point, you can add CPP files to demo2’s project, and then write code faster.

Add:

After the code is written and compiled successfully, the dll may not be found.

As long as you add the directory D: opencv / build / x86 / vc10 / bin to the environment variable path.

Special reminder:

During configuration:

1. Please identify the platform you need: x86 or x64!

2. Pay attention to the consistency of each directory and platform!

3. Add environment variable!

The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.