Summary:
Due to the recent AR (augmented reality) concept is very hot, a variety of AR-based applications and games are gradually facing the public, and in the AR is the most important two technology is tracking recognition and enhanced rendering, in which tracking recognition is through OPENCV this open-source computer vision Library to achieve, so I want to study this library, Here is a personal study note, not an authoritative tutorial, if you have errors also trouble to help me point out Kazakhstan.
============================================= Split Line ==================================================
Objective:
What is OpenCV? It may be unclear, simply, that the Opencv--open source computer Vision Library, the open source computer vision database, is based on C and some C + + languages and can be used in computer vision, Image processing and pattern recognition and tracking.
First, the preparatory work:
1. Download the OPENCV installation package:
To OpenCV's official website (http://opencv.org/) to download the latest version of the OPENCV installation package, because OPENCV for different platforms have installed programs, so we only need to choose the right platform version according to the current development environment, here we are in Win7 64bit operating system is under development, so you should download OpenCV for Windows:
We have selected the current latest version 3.1, after downloading, we get its installation file:Opencv-3.1.0.exe
2. Install Visual Studio 2015
Second, installation configuration:
1. Installation:
Double-click to open the downloaded Opencv-3.1.0.exe file, install (in fact, unzip), select the installation directory:
After installation, you can see two folders in its installation directory:build and sources, where build is the library file to use when OPENCV is used, And sources in the OPENCV for us to provide some demo model source:
2. Environment variable configuration:
The above steps just completed the installation, but to be able to use the OPENCV for development, we also need to configure the environment variables, my computer, properties, such as advanced system settings environment variables, find the PATH variable, select and click Edit:
64-bit system needs to be added in path "; OPENCV Installation path \build\x64\vc14\bin "(Note: English input method in the"; " is a separator, which is used to separate the configuration parameters of the previous software, for example, my configuration parameters should be:; E:\OpenCV\opencv\build\x64\vc14\bin. The 32-bit system should configure the path when configured in the previous OPENCV version "; OPENCV Installation path \build\x86\vc14\bin ", but the 3.1.0 version of OpenCV has deleted the x86 directory, which means that 32-bit OPENCV compilation is not possible in the VS 2015 Environment .
Another thing to note is that the x64 folder is divided into Vc12 and vc14 two folders, they correspond to the version of VS, for example VS2013 should use vc2012, and here we use vs 2015, so you should use the Vc14 file directory:
supplemental:VC8 = Visual Studio 2005,VC9 = Visual Studio 2008,VC10 = Visual Studio 2010,VC11 = Visual Studio 2012,VC12 = V isual Studio 2013,VC14 = Visual Studio 2015
Note: After the environment variable is configured, you need to restart your computer to take effect!
3.VS 2015 configuration:
We know that to use the external class library in VS, we need to introduce a configuration that includes: External library directory Designations and external include file designations.
Open vs 2015, create a new blank Win32 Console Project :
Select the language for the console project in the C++,win32 type, and set the project name:
Designation of the established Project as Blank project:
After the project is completed, we select the resource files directory (i.e. source directory) in the solution bar and create a new C + + source file:
Set the file name of the source code, for example: Main, and then create this source file into the project:
In VS there is a tool called " Property manager " for the configuration of vs overall parameters, once configured, all new projects can be used to change the configuration, no more configuration operations, easy to use. On the toolbar, click: View->other windows->property Manger to open the property manager:
In the newly emerged property manager bar, expand Directories, select debug| Win64 in the Microsoft.Cpp.x64.user, and right click on the property (properties) to enter the property interface:
1) configuration include directory:
In the common attributes (Common properties)->VC + + directory, include the contents and click on the right triangle to select Edit to enter:
Add the following three paths to them:
E:\OpenCV\opencv\build\include
E:\OpenCV\opencv\build\include\opencv
E:\OpenCV\opencv\build\include\opencv2
2) Configure the library file directory:
After completing the above included directory configuration, we also need to configure the library file: Go back to the property interface and select the library directories (libraries file directory) under the directory containing:
Add the OpenCV library file directory to the library file directory: E:\OpenCV\opencv\build\x64\vc14\lib, this directory is selected according to the directory selected by each person in the first step installation OpenCV:
3) Configure the dynamic link library:
We can look at step 2) to add the library files directory below the list of. lib files, found in the 3.1.0 version of OpenCV, only two libraries are left, respectively:opencv_world310.lib and opencv_ World310d.lib, the difference between the two library files is thatOpencv_world310.lib is the release mode version, and opencv_world310d.lib is the debug mode version:
Similar to the above two steps, open the linker (link library)->input (input)->additional Dependencies (add dependency) in the property interface:
Add one of the two library files we just saw in the OpenCV library file directory (depending on the mode requirement release mode or debug mode):
In fact, for the release and the upcoming release of the new version of OpenCV, just look at the Opencv\build\x86\vc10\lib under the library is which several, added to the dependency on it .
Third, Practice:
After all of the above configuration work has been done, we need to perform a measurement to verify that the above configuration was successful. Here our test demo function is very simple, is to display one of our designated images in a window. Add the following code to the previous Main.cpp file:
#include <iostream>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>using namespace CV; int main () {//read in a picture (game original) Mat img= Imread ("pic.jpg"); Create a name that is named"Game original Painting"window Namedwindow ("Game original Painting"); //display the game's original picture in the window imshow ("Game original Painting", IMG); //Wait 6000 ms after the window automatically shuts down Waitkey (6000); }
Copy the picture pic.jpg to the project directory, in the same directory as the source code:
Run the project, if everything is normal, the following results will appear:
Iv. issues that may arise:
1. Run the program, found that the compilation does not pass, report the error:
The reason for this error is that we said earlier that we were not able to compile 32-bit OpenCV in VS 2015, and that our entire configuration was for a 64-bit system, so how can we make vs 2015 run the debug mode of 64 , which is actually very simple, It's good to switch between the toolbars:
2. Unable to load picture, prompt pointer offside:
There are generally two possible reasons for this problem:
First, the image suffix is incorrect or the directory location is not correct;
Second, in the dynamic library configuration in the property configuration, the configuration of two libraries with D and without D does not correspond to the current debug mode, you can select the current project directly in the solution, right-click into the Properties panel, and modify the additional Dependencies in its linker:
OPENCV Study Notes (i)--OPENCV3.1.0+VS2015 development environment Configuration