win10+vs2017+opencv4.0.1+opencv contrib-4.0.1 detailed tutorial

Hits: 0

win10+vs2017+opencv4.0.1+opencv_contrib-4.0.1 detailed tutorial)

This article is taken from Bubble_water’s blog, the
original link: /fengxinzioo/article/details/88767399#commentBox

preparation tools

cmake、vs2017、opencv4.0.1、opencv_contrib-4.0.1

1. First install cmake

Official address https://cmake.org/download/

Download and install cmake-3.13.2-win64-x64.msi, which is installed by default.
Second, install VS2017

You can download it directly from Microsoft’s official website here. Link: https://visualstudio.microsoft.com/en-hans/.

All three versions can be selected. Community 2017 is a free community version. Professional 2017 and Enterprise 2017 are paid versions. There seems to be no difference in functions. I choose the Professional version here.
The paid version can be activated with a key. Here are two keys. If you can’t use it, you can find it online. There are many:
Professional 2017: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH
Enterprise 2017: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF

3. Download and install opencv_contrib

  1. Download link: https://github.com/opencv/opencv_contrib/releases . 2. Select the contrib version corresponding to your opencv. For example, I installed opencv4.0.1, and download opencv_contrib-4.0.1.zip accordingly [.]
    After the download is complete, you can directly decompress it and keep cmake for use.

opencv_contrib-4.0.1.zip is decompressed as shown below:

Fourth, extract opencv4.0.1

  1. Opencv official website: https://opencv.org/releases.html
  2. The extraction process is as follows:

5. CMake compilation

  1. Open CMake, enter the sources directory of Opencv (mine is opencv4.0.1) in the first red box in the figure below (note: it is not the directory of opencv_contrib, the original directory of your own opencv); the first red box enters your custom output directory. Finally, click Configure in the lower left corner
  2. After clicking Configure , the following prompt will appear, click OK and it will be ok
  3. Then select the version corresponding to vs, select Win64 for 64-bit system, and the default is Win32.
  4. Then wait. After that, Configuring done is displayed . The first source configuration is completed (the list does not appear red after completion).
  5. If it is red as above, you need to click Configure again until the red color does not appear to complete.

  6. After completing the above, find the OPENCV_EXTRA_MODULES_RATH item, add the modules directory in the opencv_contrib you just decompressed, and select OPENCV_ENABLE_NONFREE (the line above the red box in the figure below), and finally click Generate to start compiling.

Be careful not to copy the path, you need to select the path through cmake!
7. After completion, Configuring done and Generating done are displayed in the lower left corner.

  1. After completion, if you find the OpenCV.sln file in your output folder , it means that the compilation was completed successfully.

Six, VS2017 compilation

  1. Use VS2017 to open the ” OpenCV.sln ” file just now, it will react for a while as shown in the following figure:
  2. Then click “Generate -> Regenerate Solution” as shown in the figure , it will take a while
  3. After completion, as shown in the following figure:
  4. “Solution Explorer -> CMakeTargets -> INSTALL -> For project only -> Only generate INSTALL (B) ” and then wait for a while
    after finishing
  5. Finally, go to the custom folder to confirm, find the install folder, and go in to view the contents (as shown in the figure below, note: for the configuration environment behind, the install folder acts like the build folder when configuring opencv4.0 Same):

7. Environment configuration

1. Environment variable configuration

  1. Right-click the computer [Properties]
  2. [Advanced System Settings]
  3. [Environment Variables]
  4. [System Variables] [Path]
    Compile directory “D:\opencv4.0.1\opencv\CMAKE_opencv4.0.1_vs2017_x64\install\x64\ vc15\bin” (as shown in the figure below), modify it according to your own Cmake path.

2. Configure related directories

1. Open VS2017 and create a new empty project
Enter the name, select the build folder, and then select “Empty Project”, just confirm it directly.
After confirming, go directly to this interface, first change the X86 of Debug to X64, Opencv4.0 officially does not provide X86, if you need it, you should be able to cmake it yourself (I haven’t tried it, I’m talking irresponsibly).
Then find the property manager, as shown below:
Create a property sheet as shown in the following figure
Name the property sheet according to your easy-to-remember naming style.
Open the property sheet you just created
2. Include directory
Double-click the property sheet, and add in General Properties -> VC++ Directory -> Include Directory:
D:\opencv4.0.1\opencv\CMAKE_opencv4.0.1_vs2017_x64\install\include

D:\opencv4.0.1\opencv\CMAKE_opencv4.0.1_vs2017_x64\install\include\opencv2

Modify according to your path

There is no previous “…opencv4.0\build\include\opencv”.
3. Then add the lib directory, add in the general properties -> VC++ directory -> library directory:
4. Add in Common Properties -> Linker -> Input -> Additional Dependencies:

opencv_aruco401d.lib
opencv_bgsegm401d.lib
opencv_bioinspired401d.lib
opencv_calib3d401d.lib
opencv_ccalib401d.lib
opencv_core401d.lib
opencv_datasets401d.lib
opencv_dnn401d.lib
opencv_dnn_objdetect401d.lib
opencv_dpm401d.lib
opencv_face401d.lib
opencv_features2d401d.lib
opencv_flann401d.lib
opencv_fuzzy401d.lib
opencv_gapi401d.lib
opencv_hdf401d.lib
opencv_hfs401d.lib
opencv_highgui401d.lib
opencv_imgcodecs401d.lib
opencv_imgproc401d.lib
opencv_img_hash401d.lib
opencv_line_descriptor401d.lib
opencv_ml401d.lib
opencv_objdetect401d.lib
opencv_optflow401d.lib
opencv_phase_unwrapping401d.lib
opencv_photo401d.lib
opencv_plot401d.lib
opencv_reg401d.lib
opencv_rgbd401d.lib
opencv_saliency401d.lib
opencv_shape401d.lib
opencv_stereo401d.lib
opencv_stitching401d.lib
opencv_structured_light401d.lib
opencv_superres401d.lib
opencv_surface_matching401d.lib
opencv_text401d.lib
opencv_tracking401d.lib
opencv_video401d.lib
opencv_videoio401d.lib
opencv_videostab401d.lib
opencv_xfeatures2d401d.lib
opencv_ximgproc401d.lib
opencv_xobjdetect401d.lib
opencv_xphoto401d.lib
opencv_aruco401d.lib
opencv_bgsegm401d.lib
opencv_bioinspired401d.lib
opencv_calib3d401d.lib
opencv_ccalib401d.lib
opencv_core401d.lib
opencv_datasets401d.lib
opencv_dnn401d.lib
opencv_dnn_objdetect401d.lib
opencv_dpm401d.lib
opencv_face401d.lib
opencv_features2d401d.lib
opencv_flann401d.lib
opencv_fuzzy401d.lib
opencv_gapi401d.lib
opencv_hdf401d.lib
opencv_hfs401d.lib
opencv_highgui401d.lib
opencv_imgcodecs401d.lib
opencv_imgproc401d.lib
opencv_img_hash401d.lib
opencv_line_descriptor401d.lib
opencv_ml401d.lib
opencv_objdetect401d.lib
opencv_optflow401d.lib
opencv_phase_unwrapping401d.lib
opencv_photo401d.lib
opencv_plot401d.lib
opencv_reg401d.lib
opencv_rgbd401d.lib
opencv_saliency401d.lib
opencv_shape401d.lib
opencv_stereo401d.lib
opencv_stitching401d.lib
opencv_structured_light401d.lib
opencv_superres401d.lib
opencv_surface_matching401d.lib
opencv_text401d.lib
opencv_tracking401d.lib
opencv_video401d.lib
opencv_videoio401d.lib
opencv_videostab401d.lib
opencv_xfeatures2d401d.lib
opencv_ximgproc401d.lib
opencv_xobjdetect401d.lib
opencv_xphoto401d.lib

Other versions can change the number “401d” to their corresponding version according to their own version number (401d means the debug mode of version 4.0.1).
If your version number is different from mine, you can refer to the method at the end of my blog to use the cmd command to get all the file names in the folder:
link: /weixin_41991128/article/details/83864713 .

  1. Get your own link library list:
    Now open the directory of your corresponding path, and there is an additional 0.txt file, which stores the names of all link libraries in your folder.

Note: Remember to delete 0.txt otherwise it will affect the later, and there are 0.txt, OpenCVConfig.cmake, OpenCVConfig-version.cmake, OpenCVModules.cmake, OpenCVModules-debug.cmake in the 0.txt file , remember to delete these redundant content when copying.

8. Program verification

The verification code is as follows:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    Mat box = imread("1.jpg");
    Mat box_in_sence = imread("2.jpg");

    auto akaze_detector = AKAZE::create();
    vector<KeyPoint> kpts_01, kpts_02;
    Mat descriptors1, descriptors2;
    akaze_detector->detectAndCompute(box, Mat(), kpts_01, descriptors1);
    akaze_detector->detectAndCompute(box_in_sence, Mat(), kpts_02, descriptors2);

    // Define descriptor matching - brute force matching
    Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);
    std::vector< DMatch > matches;
    matcher->match(descriptors1, descriptors2, matches);

    // draw match
    Mat img_matches;
    drawMatches(box, kpts_01, box_in_sence, kpts_02, matches, img_matches);
    imshow("AKAZE-Matches", img_matches);
    imwrite("D:/result.png", img_matches);

    waitKey(0);
    return 0;
}

Result picture:
The original blogger of the code has uploaded it to Baidu Cloud
Link: https://pan.baidu.com/s/14Qp_moTk-7XUscftKYHQRQ
Extraction code: 67rk

reference:

/weixin_41991128/article/details/83656543

/qq_38629044/article/details/85936014

/weixin_41991128/article/details/84593477

Leave a Reply

Your email address will not be published.