Opencv (C++) series learning ---opencv_contrib installation

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:

e95dbab1bf644eda9cf90179acf95754.png

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:

5fb6aa40fc684a3c91f9232718781348.png

d156bf06bb7e4d758435a94a7bb2291d.png

 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:

fca829d583cc4947860fcfd42659bcd2.png

 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

62e1dcc7c9c24efc93b69165d1e7c423.png

 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:

9f7fd3af5481490f94d2f673565d653d.png

 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: 

6fd906aac842415db85568dc7af3c0d7.png

After the compilation is complete, the message box is Genrate done, as shown in the figure below.

dba1a1278d344f2ca565c8dfdba5a17e.png

 (4) The fourth step

Under the newly created compiled file, find Opencv.sln and double-click to open it

8d67e46df90f4fc0bb2ad228e2ee39a5.png

After opening, as shown in the figure below:

5d48277419b0450081f56234cb30f3a8.png

Select debug or release (generally speaking, both must be compiled), corresponding to the operating system X64

deb5e0b0702444b195ef9a9f4eb2f670.png

 After the solution is generated, if there is no error, click INSTALL= "Only for projects = "Generate only

6862926f707e4176ba7a0c626ce25692.png

 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

c8f2dcb0ad464f37948f5d7cb280c5aa.png

7b22a456aff24f7b98772c730c285c1f.png

3c31c1b1afaf442eb2ac883d50e45dfb.png

cc2762bb3eb9416d9bde5cdaf1457e8a.png

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

85d5b4657f774b0092641622fdf5b3b6.png

 The include directory is: D:\opencv\opencv_contrib_build\install\include D:\opencv\opencv_contrib_build\install\include\opencv2

fcbbe008c2bd498b8a3a1c5c4752eb6f.png

 6d98ea76e4ef43369fb8a1ca70d00e67.png 

The library directory is: D:\opencv\opencv_contrib_build\install\x64\vc14\lib

e27b346a478442d79d2b2f1e531ece5b.png

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:

fab2c793bfbd4b73991b2d74b2260e27.png

If you can successfully run the above code, congratulations, you have completed the configuration of opencv and its contrib!

おすすめ

転載: blog.csdn.net/qiaodahua/article/details/127987767