Introduction to OpenCV library files

Reprint the article, the address statement is at the end of the article!

 

1、build和source

When we install opencv, you will find that there are two folders in the opencv folder, build and source, what do they do respectively.

write picture description here

First of all, let’s talk about the relationship between the two. The sources put the cpp file in opencv, which is equivalent to a factory, and the build put the h, hpp, and lib files in opencv, which is equivalent to a tool. The developers of opencv (of course after open source) Users can also) build the library files in the build through the source files in sources, and then users can link these libraries and include <header file>. Generally, non-open source programs and libraries are not open sources, and as an open source library, opencv is also visible to users.

There are various function implementations in the source. For those who only want to use opencv, they only care about how I use them, so developers will use these source files to build libraries, which contain function implementations. These libraries are various libs, and then there are header files.

There are only interfaces in the build, and there is no implementation in cpp. The build is for the user. The user only needs to know the interface, and does not need to know how this is done. Of course, because opencv is open source, users can also view the source files directly.

Specifically, the specific implementation of the function is placed in the soucees, such as the gray method, how to make the pixels of a mat grayscale.

The user includes <header file>, the header file contains various interfaces, such as gray, which is a gray (MAt img), the user links these libraries, inluce <header file>, and then calls gray in the program, and then the program runs When linking, look for the implementation of gray in various dependent libraries. Because we connected the library of opencv, we found the implementation of gray in the lib of opencv, and then called this implementation, and then grayed it out. , this is the process.

To give an inappropriate example, build is like a macbook sold to users. Users only need to know how to use it. This operating system is very easy to use, and it is not stuck. There is no need to know how this operating system is implemented. How to achieve it is in the source. It is impossible for you to see the source for non-open source programs and libraries.

2、build

In the build folder, as follows,

write picture description here 
.

First of all, the doc folder contains various documents about opencv; the include folder contains all the header files; the other four are: one for java library, one for python, one for x86win, one for x86win For x64win. The two cmake files are some configurations of cmake, very powerful compilation tools.

2.1 include

Divided into opencv and opencv2.

write picture description here

write picture description here 
.

The introduction of blog 1 and blog 2 is borrowed here .

1、opencv

The header files included in cv.h:

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/flann/flann.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/legacy/compat.hpp"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

The header files are included in cv.hpp:

#include <cv.h>
  • 1

That is to say, cv.hpp contains cv.h. Wherever cv.h is used in the program, it can be replaced by cv.hpp, so why should the hpp file be set?

hpp is short for Header Plus Plus,  similar to .h files. But the difference is that .hpp also writes the implementation code in *.cpp, so that both the definition and the implementation are included in the same file. The benefits of doing this are obvious, no need to add cpp files to the project to compile, reduce the number of compilations, and do not need to publish annoying lib, dll files, so it is very suitable for writing public open source libraries.

The header files in the folder opencv are similar, including the header files in the folder opencv2. So if we are learning from a low version of opencv and transitioning to a high version of opencv, if we don't adapt, we can use the file call in the opencv folder as the standard. If you are familiar with the function distribution in opencv, you can also directly call the specific header files in the opencv2 folder, so that pre-compiling the header files improves efficiency.

2、opencv2

First look at the opencv.hpp file:

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

Obviously the header file of opencv.hpp contains all the header files in the opencv library.

Then look at the opencv_modules.hpp file:

#define HAVE_OPENCV_CALIB3D
#define HAVE_OPENCV_CONTRIB
#define HAVE_OPENCV_CORE
#define HAVE_OPENCV_FEATURES2D
#define HAVE_OPENCV_FLANN
#define HAVE_OPENCV_GPU
#define HAVE_OPENCV_HIGHGUI
#define HAVE_OPENCV_IMGPROC
#define HAVE_OPENCV_LEGACY
#define HAVE_OPENCV_ML
#define HAVE_OPENCV_NONFREE
#define HAVE_OPENCV_OBJDETECT
#define HAVE_OPENCV_OCL
#define HAVE_OPENCV_PHOTO
#define HAVE_OPENCV_STITCHING
#define HAVE_OPENCV_SUPERRES
#define HAVE_OPENCV_TS
#define HAVE_OPENCV_VIDEO
#define HAVE_OPENCV_VIDEOSTAB
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

It is explained as follows:

[calib3d]: In fact, it is the combination abbreviation of Calibration and 3D. This module is mainly related to camera calibration and 3D reconstruction. Basic multi-view geometric algorithms, single stereo camera calibration, object pose estimation, stereo similarity algorithms, reconstruction of 3D information, etc.

[contrib]: The abbreviation of Contributed/Experimental Stuf, this module contains some recently added unstable optional functions, so you don't need to go overboard. After 2.4.8, there are new face recognition, stereo matching, artificial retina model and other technologies.

[core]:  Core functional modules, especially the underlying data structures and algorithm functions. Contains the following:

  • OpenCV basic data structure
  • dynamic data structure
  • drawing function
  • Array manipulation related functions
  • Accessibility and System Functions and Macros

[imgproc]:  The abbreviation combination of the words Image and Processing. Image processing module, this module includes the following:

  • Linear and nonlinear image filtering
  • Geometric transformation of images
  • Miscellaneous image conversion
  • Histogram correlation
  • Structural Analysis and Shape Description
  • Motion Analysis and Object Tracking
  • Feature detection

[features2]:  d is Features2D, a 2D functional framework, including interest point detectors, descriptors, and interest point matching frameworks. Contains the following:

  • Feature detection and description
  • Feature Detectors Generic Interface
  • Descriptor Extractors generic interface
  • Descriptor Matchers generic interface
  • Generic Descriptor matcher generic interface

[flann]:  Fast Library for Approximate Nearest Neighbors, a high-dimensional approximate nearest neighbor fast search algorithm library, including two parts: fast approximate nearest neighbor search and clustering.

[gpu]:  A computer vision module that uses GPU acceleration.

[highgui]:  that is, high gui, a high-level GUI graphical user interface, including media I/O input and output, video capture, image and video encoding and decoding, and graphical interface interfaces.

[legacy]:  Some code bases that have been abandoned are retained for backward compatibility, including the following related content.

  • motion analysis
  • expectation maximization
  • Histogram
  • Flat Subdivision (C API)
  • Feature Detection and Description
  • Generic interface for Descriptor Extractors
  • Common interface for Generic Descriptor Matchers

[ml]:  Machine Learning, a machine learning module, basically a statistical model and a classification algorithm, including the following.

  • Statistical Models
  • Normal Bayes Classifier
  • K-Nearest Neighbors
  • Support Vector Machines
  • Decision Trees
  • Boosting
  • Gradient Boosted Trees
  • Random Trees
  • Extremely randomized trees
  • Expectation Maximization
  • Neural Networks
  • MLData

[nonfree]:  that is, some patented algorithm modules, including feature detection and GPU-related content. It's best not to use it for commercial use, you may be accused.

[objdetect]:  Target detection module, including Cascade Classification and Latent SVM.

[ocl]:  OpenCL-accelerated Computer Vision, a computer vision component module accelerated by OpenCL.

【photo】:  Computational Photography, including image restoration and image denoising.

[stitching]:  images stitching, image stitching module, including the following parts.

  • Splicing pipeline
  • Features Find and match images
  • Estimated rotation
  • Automatic calibration
  • Picture is skewed
  • seam estimation
  • Exposure Compensation
  • image mix

[superres]:  SuperResolution, related functional modules of super-resolution technology.

[ts]:  opencv test related code, don't worry about it.

[video]:  Video analysis component, which includes video processing related content such as motion estimation, background separation, and object tracking.

[Videostab]:  Video stabilization, components related to video stabilization.

2.2 X64 and X86

First of all, there are some library files in it, but X64 is 64-bit, and X86 is 32-bit. Then take X64 as an example,


write picture description here 
.

This is a library for compiling to different versions of visual studio. Here we take vc12 as an example.


write picture description here 
.

Under the bin folder: dll files, dynamic link libraries. specific implementation content. In the computer environment variable, this path is to be added to the path.

Under the lib folder: the lib library added when configuring the opencv environment. used to link.

Under the staticlib folder: static library.

The static library loads the entire function at compile time, so the executable file will become larger. The dynamic library is a function table added at compile time, and the corresponding function implementation will be loaded from the dll at runtime.

Refer to the blog here to give an explanation about dll and lib.

There are two kinds of libraries:

  • One is that the LIB contains the information (entry) of the DLL file where the function is located and the function location in the file. The code is provided by the DLL loaded in the process space at runtime, which is called the dynamic link library.
  • One is that the LIB contains the function code itself, and the code is directly added to the program at compile time, which is called the static link library.

There are two ways to link:

  • Dynamic linking uses a dynamic link library that allows an executable module (.dll file or .exe file) to contain only the information needed to locate the executable code of the DLL function at runtime.
  • Static linking uses a static link library, the linker gets all the referenced functions from the static link library LIB and puts the library together with the code into the executable file.

The difference between lib and dll is as follows:

  • lib is used at compile time, dll is used at runtime. If you want to compile the source code, you only need lib; if you want to run the dynamically linked program, you only need dll.

  • If there is a dll file, then lib is generally some index information, which records the entry and location of the function in the dll, and the specific content of the function in the dll; if there is only a lib file, then the lib file is statically compiled, and both the index and the implementation are in it. Using statically compiled lib files, you do not need to hang the dynamic library when running the program. The disadvantage is that the application is relatively large, and the flexibility of the dynamic library is lost. When a new version is released, a new application must be released.

  • In the case of dynamic linking, there are two files: one is the LIB file and the other is the DLL file. The LIB contains the names and locations of the functions exported by the DLL, the DLL contains the actual functions and data, and the application uses the LIB file to link to the DLL file. In the executable file of the application, instead of the called function code, the address of the corresponding function code in the DLL is stored, thereby saving memory resources. DLL and LIB files must be distributed with the application, otherwise the application will generate errors. If you don't want to use the lib file or there is no lib file, you can use the WIN32 API functions LoadLibrary and GetProcAddress to load.

3、sources

write picture description here 

  • samples: are some short learning use cases.
  • modules: Contains all source files.
  • doc: are some documents, including some tutorials.
  • include: are all header files. Contains opencv and opencv2.
  • 3rdparty: Third-party libraries, such as ffmpeg video encoding, etc.
  • apps: some applications, such as cascade classifier, haar feature classifier.
  • cmake: Compilation related.
  • data: some data for the cascaded classifier. Such as face detection, eye detection, etc.
  • platform: platform related, iOS, Android, Linux, script, win.

Reference address: https://blog.csdn.net/liuxiao214/article/details/77882282

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324979319&siteId=291194637