foreword
Due to the increasingly bloated functions of OpenCV , OpenCV3 changed the project architecture and used the architecture form of kernel + plug-in. Therefore, OpenCV is a big change from 2.x to 3.x. Many modules with imperfect functions and unstable performance have been put into extra_modules (extension modules). In Github, in addition to storing the main warehouse of the official version of OpenCV and the newly added OpenCV_extra warehouse, a new warehouse of OpenCV_contrib has been added. The functions include: face recognition, text recognition, edge detection, tracking algorithms, etc., which are stored. Code with unstable functions, if you need to use these functions, you need to recompile.
The opencv_contrib warehouse contains most of the user-generated content, and it also has more complete computer vision algorithm applications than the core library OpenCV; there is no software dependency between modules in the opencv_contrib warehouse. Each module requires its own documentation, unit test cases, and sample code, and most modules usually include module tutorials.
【1】Preparation before installation
(1) Opencv installation
There are two types of opencv installations. The first one is to use the exe installation program, select the installation path, and do not need cmake to compile. After the installation is complete, follow the configuration process (opencv configuration documentation is in the column) to configure the system environment variables and vs environment. Configure and use. The installation package looks like this:
The second is to compile through cmake, and cmake needs to be prepared in advance.
(2) Download address
The download address of opencv and its contrib is: Index of /opencv/
The official website is: Home - OpenCV
The github address is: OpenCV GitHub
The cmake download address is: Download | CMake
(Select the corresponding version of Cmake on the official website)
This article will not go into details about the configuration of opencv. This article specifically talks about how to configure contrib on the basis of opencv configuration. (If opencv is not configured, you can also install this process to realize the common configuration of opencv and its contrib.)
Be careful! ! ! opencv and its contrib version must be consistent! ! ! !
cout<<CV_VERSION<<endl;
If you don't know your own opencv version, enter this statement in the program to query.
After the download is complete, as shown below:
The source is the source file of opencv. In the installation directory of opencv, put the downloaded contrib file together with it, and create a new opencv_contrib_build file to store the compiled file.
[2] cmake compiles
first step:
1. Compile the source path of Opencv for cmake.
2. It is the path to store the compiled files after the new compilation. (The opencv_contrib_build file has been compiled, I replaced it with test)
3. Click configure
Select the vs version corresponding to the computer, the system operation type, and click FINISH.
(2) The second step
After the first Configure is completed, find OPENCV_EXTRA_MODULES_PATH, and then select the modules directory in the opencv_contrib directory, as shown below:
After selecting the directory, click the configure button for the second time
(3) The third step
When configure done appears in the interface, click the Genrate button, as shown in the figure:
After the compilation is complete, the message box is Genrate done, as shown in the figure below.
(4) The fourth step
Under the newly created compiled file, find Opencv.sln and double-click to open it
After opening, as shown in the figure below:
Select debug or release (generally speaking, both must be compiled), corresponding to the operating system X64
After the solution is generated, if there is no error, click INSTALL= "Only for projects = "Generate only
It appears that the generation is successful, which means that the lib library is generated.
【3】Environment configuration
(1) System environment configuration
Right click on this computer = "properties =" advanced system settings = "environment variables
Select Path = "New
The bin path is: D:\opencv\opencv_contrib_build\install\x64\vc14\bin
After filling in the bin path, click Finish.
(2) Configure the VS environment
Create a new project property sheet in the property manager
The include directory is: D:\opencv\opencv_contrib_build\install\include D:\opencv\opencv_contrib_build\install\include\opencv2
The library directory is: D:\opencv\opencv_contrib_build\install\x64\vc14\lib
The path lib file has many sub-files, you can find them by the following method, copy the file name to the txt file, the method is as follows:
Additional dependencies are lib files in the library directory:
1. Create a new TXT file in the folder containing the training images.
2. Enter DIR *.*/B>train.txt in the TXT file (there must be a space after the DIR command)
3. After saving, change the suffix to BAT.
4. Double-click the file to generate a train.txt.
【4】Test
The test code is as follows:
#include<opencv2\opencv.hpp>
#include<opencv2\xfeatures2d.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\xfeatures2d\nonfree.hpp>
#include<iostream>
using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;
int main(int argc,char** argv)
{
//【0】改变字体颜色
system("color 2F");
//【1】载入源图片并显示
Mat srcImage1 = imread("E:\\乔大花进度\\11-17\\surf特征检测\\1.jpg",1);
Mat srcImage2 = imread("E:\\乔大花进度\\11-17\\surf特征检测\\2.jpg", 1);
//【2】显示图片
imshow("原始图1",srcImage1);
imshow("原始图2",srcImage2);
int minHessian = 400;//默认值为100
vector<KeyPoint>keyPoints, keyPoints1;
Mat resultImg, resultImage1;
//关于定义的方法主要有两种
//第一种指针形式定义
// Ptr<SURF\SIFT\ORB>detector = SURF\SIFT\ORB::create(minHessian, 4, 3, false, false);
//第二种算子形式定义
//SiftFeatureDetector\SurfFeatureDetector定义
//第一种定义方式更普遍使用
//SURF特征检测 //也可以写成SURF::create(minHessian)
Ptr<SURF>detector = SURF::create(minHessian, 4, 3, false, false);
detector->detect(srcImage1, keyPoints, Mat());
//绘制关键点
drawKeypoints(srcImage1, keyPoints, resultImg, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
imshow("KetPoint image", resultImg);
//SIFT特征检测
Ptr<SIFT>detector1 = SIFT::create();
detector1->detect(srcImage2, keyPoints1, Mat());
//绘制关键点
drawKeypoints(srcImage2, keyPoints1, resultImage1, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow("KetPoint image1" ,resultImage1);
waitKey(0);
system("pause");
return 0;
}
Test Results:
If you can successfully run the above code, congratulations, you have completed the configuration of opencv and its contrib!