OpenCV + CPP series (32) opencv contrib extension module compilation (win10+vs2019+opencv4.5.2)

Posted by nicolam1 on Thu, 30 Dec 2021 18:06:47 +0100


The whole process: cmake configuration and generation - > VS compilation generation and installer - > Reconfigure opencv/include/libraries / additional dependencies

1, Preliminary preparation

opencv github homepage address: https://github.com/opencv/

visual studio 2019 – windows10 x64 is installed by default

  1. Download opencv4 five point two Click download
  2. Download opencv4 5.2 extension module (opencv_contrib-4.5.2) Click download
  3. Download cmake3 twenty-one Click to download the corresponding platform
  4. Opencv4 5.2 unzip to the specified disk (D:\opencv4.5.2);
  5. Set opencv4 5.2 decompress the expansion module to the specified disk (D:\opencv_contrib-4.5.2);
  6. Cmake3 21 decompress to the specified disk (D:\cmake3.21);

2, Start Cmake compilation

  1. Open Cmake software and start configuration;

  2. Add the location where Opencv source code is stored - > select the location where Cmake compiled files are saved - > configuration

  3. Select the version of the installed VS - > click Finish - > wait for the configuration to complete;

  4. Click configure, and a large area of red will appear. Here, first change some options in red: (use search to quickly find)

    ① (optional) check BUILD_opencv_world is mainly to get all lib files into an opencv_world450d.lib for easy configuration.
    If Anaconda is installed, uncheck it, otherwise opencv cannot be found after opencv is compiled_ worldxxx. lib.

    ② Check OPENCV_ENABLE_NONFREE is to use the algorithm with patent protection after successful compilation. If the variable is not selected, the algorithm with patent protection cannot be used;

    ③ Opencv found_ EXTRA_ modules_ Path variable, select the opencv we just downloaded_ modules folder in contrib installation package. If this variable is empty, only the basic version of OpenCV is installed.

    Remove modules that do not need to be compiled (optional)
    Enter test to find OPENCV_PERF_TESTS,BUILD_TESTS,BUILD_opencv_python_tests uncheck:
    Enter java to find BUILD_JAVA,BUILD_opencv_java_bingdings_generator unchecked:
    Enter Python to find BUILD_opencv_python3,BUILD_opencv_python_bingdings_generator unchecked:

    ④ View the CMakeDownloadLog file; Manually download and rename the MD5 file name to D: \ opencv-4.5 2\. Cache \ staging folder github file download acceleration (limit20M), Or accelerate here ,Or accelerate here

    If the version you compiled is the same as mine, you can use it directly: Baidu network disk shared address link , extraction code: voq1

    ⑤ Click [Configure] again until all the red colors disappear, and then click [Generate] to start compiling. If the compilation is successful, many files will be generated under D:\opencv_build

3, VS2019 compiling OpenCV source code

Click open project

Click generate - > batch generate, check ALL BUILD and INSTALL, and click generate on the right.

About an hour later:

Right click INSTALL under CMakeTargets and click [only for project] - [generate INSTALL only]:
Installation directory defined in CMake (location of generated files)

Generate debug and release respectively

4, Configure into project

The compilation is complete and ready:

  1. Configure OpenCV environment variables
    [this computer - > properties - > advanced system settings - > environment variables - > system variables - > find path - > Edit - > New],
    Add environment variable D: \ opencv_ Build \ install \ x64 \ vc16 \ Bin - > OK. (delete the opencv environment variable previously used)

  2. Configure the new library file into the project
    vs2019 configuring opencv
    Create an empty item and click item - > properties.

  3. VC + + Directory:
    Include directory: D:\opencv_build\install\include,D:\opencv_build\install\include\opencv2
    Library Directory: D:\opencv_build\install\x64\vc16\lib

  4. Linker – > input – > Add dependencies: (note that the added library should be consistent with the compilation options. Note that the debug file name is d more than the release file name). Use the command line tree /f to output the file name for easy copying and pasting.
    Copy * lib file, * 452d lib is the debug version, with 104 items in total

    opencv_aruco452.lib
    opencv_aruco452d.lib
    opencv_bgsegm452.lib
    opencv_bgsegm452d.lib
    opencv_bioinspired452.lib
    opencv_bioinspired452d.lib
    opencv_calib3d452.lib
    opencv_calib3d452d.lib
    opencv_ccalib452.lib
    opencv_ccalib452d.lib
    opencv_core452.lib
    opencv_core452d.lib
    opencv_datasets452.lib
    opencv_datasets452d.lib
    opencv_dnn452.lib
    opencv_dnn452d.lib
    opencv_dnn_objdetect452.lib
    opencv_dnn_objdetect452d.lib
    opencv_dnn_superres452.lib
    opencv_dnn_superres452d.lib
    opencv_dpm452.lib
    opencv_dpm452d.lib
    opencv_face452.lib
    opencv_face452d.lib
    opencv_features2d452.lib
    opencv_features2d452d.lib
    opencv_flann452.lib
    opencv_flann452d.lib
    opencv_fuzzy452.lib
    opencv_fuzzy452d.lib
    opencv_gapi452.lib
    opencv_gapi452d.lib
    opencv_hdf452.lib
    opencv_hdf452d.lib
    opencv_hfs452.lib
    opencv_hfs452d.lib
    opencv_highgui452.lib
    opencv_highgui452d.lib
    opencv_imgcodecs452.lib
    opencv_imgcodecs452d.lib
    opencv_imgproc452.lib
    opencv_imgproc452d.lib
    opencv_img_hash452.lib
    opencv_img_hash452d.lib
    opencv_intensity_transform452.lib
    opencv_intensity_transform452d.lib
    opencv_line_descriptor452.lib
    opencv_line_descriptor452d.lib
    opencv_mcc452.lib
    opencv_mcc452d.lib
    opencv_ml452.lib
    opencv_ml452d.lib
    opencv_objdetect452.lib
    opencv_objdetect452d.lib
    opencv_optflow452.lib
    opencv_optflow452d.lib
    opencv_phase_unwrapping452.lib
    opencv_phase_unwrapping452d.lib
    opencv_photo452.lib
    opencv_photo452d.lib
    opencv_plot452.lib
    opencv_plot452d.lib
    opencv_quality452.lib
    opencv_quality452d.lib
    opencv_rapid452.lib
    opencv_rapid452d.lib
    opencv_reg452.lib
    opencv_reg452d.lib
    opencv_rgbd452.lib
    opencv_rgbd452d.lib
    opencv_saliency452.lib
    opencv_saliency452d.lib
    opencv_shape452.lib
    opencv_shape452d.lib
    opencv_stereo452.lib
    opencv_stereo452d.lib
    opencv_stitching452.lib
    opencv_stitching452d.lib
    opencv_structured_light452.lib
    opencv_structured_light452d.lib
    opencv_superres452.lib
    opencv_superres452d.lib
    opencv_surface_matching452.lib
    opencv_surface_matching452d.lib
    opencv_text452.lib
    opencv_text452d.lib
    opencv_tracking452.lib
    opencv_tracking452d.lib
    opencv_video452.lib
    opencv_video452d.lib
    opencv_videoio452.lib
    opencv_videoio452d.lib
    opencv_videostab452.lib
    opencv_videostab452d.lib
    opencv_wechat_qrcode452.lib
    opencv_wechat_qrcode452d.lib
    opencv_xfeatures2d452.lib
    opencv_xfeatures2d452d.lib
    opencv_ximgproc452.lib
    opencv_ximgproc452d.lib
    opencv_xobjdetect452.lib
    opencv_xobjdetect452d.lib
    opencv_xphoto452.lib
    opencv_xphoto452d.lib
    

5, Testing

Since the sift patent has expired and the sift has been moved to the main library, the code is as follows: no need to #include < opencv2 / xfeatures2d hpp>

void QuickDemo::sift_Demo(Mat& image) {
	int numFeature = 500;
	Mat img_descriptors;
	cv::Ptr<SIFT> detector = SIFT::create(numFeature);

	vector<KeyPoint> KeyPoint1;
	detector->detectAndCompute(image, Mat(), KeyPoint1, img_descriptors);
	drawKeypoints(image, KeyPoint1, img_descriptors, Scalar(0, 255, 255));
	imshow("img_descriptors", img_descriptors);
}


From the beginning of this article, opencv and its expansion module in this article shall prevail.
Acknowledge
Solution to download error during compilation: https://blog.csdn.net/weixin_43851329/article/details/114335959

Topics: OpenCV