Opencv2. 4.13 and visual studio 2013 environment configuration tutorial


Opencv is a tool for image processing. The program is written in C + + language to realize the recognition algorithm, so it is necessary to configure opencv and vs environment first.

SHAINE belongs to the kind of person who can’t be counted as a halfway monk. During the three or four years of undergraduate study, she’s really half hanging, and she doesn’t know anything about the development direction. As a giser, it will inevitably involve development and graphics and image processing. Therefore, SHAINE plans to take this opportunity to start a small project by herself, starting from the needs, existing research status and referenced classical algorithms, re learn GIS development and preliminarily learn the relevant contents of OpenCV.

It took four or five days to download and install the software. It also configured the environment according to the online configuration tutorial. During the test, various exceptions were thrown and various references were incorrect, that is, it was not successful. SHAINE was puzzled at that time. Because I only learned C and c# two programming languages when I was an undergraduate, and I learned very little, and I didn’t understand C + +, which is a big obstacle. Unfortunately, the system was reinstalled and the configuration was restarted. Therefore, the lesson Shane learned is:

1. When installing the software and configuring the environment according to the online tutorial, you must first read the whole process, have a general understanding, understand its principle, and avoid pasting and copying the contents of some operation steps step by step, because everyone’s computer folder and naming are different. Only when you understand its principle can you suit the remedy to the case in 32 / 64 bit selection, version, etc, Otherwise, it will only embark on the road of constantly reconfiguring, reinstalling and even reinstalling the system.

2. Try to install only one stable and compatible version of each software on the computer, and do not install two or three versions to support the memory. Shane taught you a lesson with blood. At that time, Shane installed three different versions of VS2010 / 2013 / 2015. Do you think Shane was full and supported?

3. When installing any software, do not appear folders named in Chinese characters, whether you are installing Chinese software or English software, because once folders with Chinese names appear during the installation of English software, errors are likely to occur in path identification, so for the sake of insurance, you’d better name them in English.

4. When two or more software are involved in environment construction, it is best to find out the matching versions of the two software on the Internet before downloading and installing. For example, opencv configures vs, opencv3 2. We need vs2015 to configure, because only vc14 in vs2015 can match VC in opencv, and we can directly call the compiled class library in the software package, otherwise we have to compile manually.

Well, SHAINE is not talking nonsense. Let’s talk about the configuration steps of OpenCV and vs first.

1、 Download and installation of installation package

Opencv can be downloaded from the official website for free. Opencv is a foreign software. Due to resource constraints, the download may be slow or even fail. It’s OK. Just download it again directly.

Attach a link to the official website:

About installation, it’s better to decompress. As shown in the figure, just unzip it directly to the target folder.

Vs2013 must have been contacted by every developer and installed n times. Shane won’t repeat it here.

2、 Configuration of environment variables

Computer → right click Properties → advanced system settings → advanced → environment variables, in the user variable, click new, the variable name is opencv, and the variable value is: D: \ software \ opencv \ build (i.e. the build file path you installed openCV); system variable path, click Edit, and add D: \ software \ opencv \ build \ x86 \ vc12 \ bin.

Note: whether your system is 32-bit or 64 bit, x86 is selected as the path directory, because 32-bit compilation is used for compilation.

3、 New visual c + + Project

Open vs, create a new project, select VC + + under the template, and create a new Win32 console application. Jump out of the application wizard, click next, check the empty item in the additional options, and click finish. (the purpose of checking the blank item is to create a template for the following settings, so you don’t have to configure it every time you create a project)

Create a new C + + file (. Cpp file) in the source file of the solution.

In the attribute manager, do the following:

In debug Win32 Microsoft Cpp. Win32. Double click user to enter the property page and make the following settings:

1. General properties → VC + + Directory:

Add to include directory:




Add: D: \ software \ opencv \ build \ x86 \ vc12 \ lib to the library directory

2. General attribute → linker → input → attach dependency, and input items in lib Library in dependency Lib file name:



















opencv_videostab2413d.lib on release Win32 Cpp. Win32. Double click user to enter the property page and perform the same operations as those in debug. In fact, the above are all lib files under D: \ software \ opencv \ build \ x86 \ vc12 \ lib. You will find that some are followed by D and some are not. This is because there is d in debug and no D in release.

4、 Final test

Shane tests the accuracy of the entire configuration process by displaying a picture.

Create a new one Cpp file, enter the following code:

Pay attention to the input format of the image path of the code certificate. The original directory of the images in Shane is as follows: D: \ Lihong \ blind way recognition \ myproject \ test1_ 0228 ; But have you noticed that in the input of the whole path, all “\” become “\ \”, and “\ \” should be added even when adding the file name.

The operation results are as follows:

So far, the whole configuration process has been successfully completed.

5、 Other instructions

During the test, you may encounter the following problems like SHAINE:

1. In VC + + “skip when finding precompiled header”

The reason for this is that “StdAfx. H” is not added #include in the front line of cpp file. The solution is:

Method 1: remove the precompiled header

Project → attribute → configure attribute → C / C + + → precompiled header → create and use precompiled header → do not use precompiled header

Method 2: add the included file to the precompiled header StdAfx H file

Law 3: in every CPP contains the precompiled header StdAfx H file

Note: #include “StdAfx. H” must be added to the first line of the cpp file.

2. After debugging the solution, a pile of similar to window \ syswow64 \ gdi32 will appear DLL could not find or open the pdb file because of a problem The DLL library is not properly linked so that the relevant classes cannot be called during debugging

Debugging → options and settings → debugging → general → check “enable resource server”

Debugging → options and settings → debugging → general → check “Microsoft symbol server”

In fact, in the end, even if Shane has run the whole test project, there are still a few DLLs that cannot be called. Shane is also very headache and depressed. She has to keep looking for reasons.

Note: after many experiments, SHAINE always reported the errors in the figure below. Later, she consulted a senior student. The reason is that too many configurations may lead to the error of additional dependencies. She deleted the contents of additional dependencies and added them again without checking the options in the lower left corner. Save the settings and vs, close the project and reopen it to solve the problem.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

Summary of import and export usage in JavaScript

import import 和 require 的区别 import 和js的发展历史息息相关,历史上 js没有模块(module)体系,无法将一个大程序拆分成互相依赖的小文件,再用简单的方法拼装起来。这对开发大型工程非常不方便。在 ES6 之前,社区制定了一些模块加载方案,最主要的有 CommonJS 和 AMD 两种。前者用于服务器,后者用于浏览器。ES6 在语言标准的层面上,实现了模块功能,而且实现得相当简单,完全可以取代 CommonJS 和 AMD 规范,成为浏览器和服务器通用的模块解决方案。也就是我们常见的 require 方法。 比如 `let { stat, exists, readFile } = require(‘fs’);` 。ES6 在语言标准的层面上,实现了模块功能。ES6 模块不是对象,而是通过export命令显式指定输出的代码,再通过import命令输入。 import 的几种用法: 1. import defaultName from ‘modules.js’; 2. import { export } from ‘modules’; 3. import { export as ex1 } from […]