In the process of compiling OpenCV 4.7.0 under Win10, I stepped on a few pits, which are recorded here for your reference.
1. Download the source file
Download the source file of OpenCV 4.7.0 and opencv_contrib-4.7.0 from GitHub. If it is not convenient to download, the following is the link of Baidu Netdisk. You can pick it up if you need it
Link: https://pan.baidu.com/s/1qP2aL9712YtuYM1zBeh1bg?pwd=7btf
Extraction code: 7btf
It is recommended to download all three files, and opencv_3rdparty will be useful later.
2. Unzip opencv-4.7.0.zip, and create a new build folder in opencv-4.7.0
3. Open Cmake-gui, set the source file path and build path
Select the VS2019 and x64 options and click Finish.
4. Output "extra" in the Search box, and configure the EXTRA_MODULES path (decompress opencv_contrib-4.7.0.zip in advance)
5. Click the Configure button and wait quietly for completion. This process will be configured according to CmakeLists.txt, and some files will be automatically downloaded from the Internet. For example, download third-party files such as xfeatures2d_boostdesc and xfeatures2d_vgg.
If the download of files such as xfeatures2d_boostdesc and xfeatures2d_vgg fails during this process, you can decompress the opencv_3rdparty.zip file shared by my network disk to the download folder of the build, as shown in the figure below.
If the third-party file is missing, an unresolvable external symbol cv::xfeatures2d::VGG::getDefaultName will be reported during subsequent compilation. For details, please refer to my post Compile OpenCV 4.7.0 Unresolvable external symbol cv:: xfeatures2d ::VGG::getDefaultName problem solved_NOAHCHAN1987's Blog-CSDN Blog
Note: The download address of the third-party file:
GitHub - opencv/opencv_3rdparty at wechat_qrcode_20210119
GitHub - opencv/opencv_3rdparty at contrib_xfeatures2d_vgg_20160317
GitHub - opencv/opencv_3rdparty at contrib_xfeatures2d_boostdesc_20161012
If you want to download it yourself from GitHub, you can download it directly from the above address.
6. When configuring Configure, check NONFREE, otherwise C++ will report an error when calling SURF::create
Reference: OpenCV 4.7.0 calls SURF::create to solve the error problem_NOAHCHAN1987's Blog-CSDN Blog
7. If you don't need java and python, uncheck it to save subsequent compilation time.
You can also cancel the checks of various tests
8. According to your own usage habits, choose whether to generate the opencv_world library (if not checked, the library will be generated according to the module when compiling), I personally like to use the opencv_world library, although the library is a bit bloated, it is more convenient.
9. Set the installation path
10. After everything is set, click the Configure button again. After Configuring done, click the Generate button to generate the project.
11. Click Open Project or in the build directory, open OpenCV.sln with VS2019
Pay attention to select Release/Debug
Right click on "ALL_BUILD" and click "Build"
After about ten minutes, the compilation is complete
Right click on "INSTALL" and click "Generate"
Eventually, the OpenCV header files and libraries will be copied to the install path.
finish, enjoy