[opencv] [CPU] opencv4.8.0-cuda C++ version source code compilation tutorial under windows10

[opencv] [CPU] opencv4.8.0-cuda C++ version source code compilation tutorial under windows10

Tip: The blogger has selected many blog posts from big guys and personally tested them to be effective. He shares his notes and invites everyone to study and discuss them together.


Preface

OpenCV is an open source computer vision library that includes core modules and extension modules, providing basic image processing and computer vision algorithms, as well as some machine learning tools. OpenCV Contrib is one of a set of extension modules contributed by the OpenCV community. It contains some relatively novel and practical algorithms and tool functions, and provides some advanced image processing and computer vision algorithms. These features and algorithms may not be suitable for all users or may be experimental. The code in the OpenCV Contrib module is developed and maintained by community contributors, and they provide new features and experimental functionality not yet included in the OpenCV core library.

For some users, it is very convenient to download Family Bucket from the official website without compilation process. For users who do not want to spend time and energy compiling, this is the easiest option. But for most developers, by compiling from source, they can customize settings according to their own needs: enable or disable specific features, optimize compilation options, and add their own modifications. This provides you with greater flexibility and control. Here is a comparison of the locally compiled opencv (left) and the officially downloaded opencv (right). The file size can be reduced a lot.


Preparation tools

cmake、vs2019、opencv4.8.0、opencv_contrib-4.8.0

cmake

CMake official download address, download cmake-3.27.7-windows-x86_64.msi.

The blogger added to the environment and installation path and made modifications according to his own situation. Others are installed by default.

The following interface appears and the installation is successful.

opencv4.8.0

Opencv official download address, download OpenCV – 4.8.0 Sources, download and decompress opencv-4.8.0.zip.

opencv_contrib

opencv_contrib official download address, select the contrib version corresponding to opencv, for example, opencv4.8.0 corresponds to opencv_contrib-4.8.0.zip. Unzip it directly after downloading.


CMake compilation

  1. Open CMake, where is the source code is the folder location of Opencv sources (the blogger is opencv-4.8.0), where to build the binaries is the folder location where opencv is saved (customized), the first time in the lower left corner Click Configure.
  2. Select the version corresponding to vs (the blogger is vs2019), select x64 for the system, and finally click Finish in the lower right corner.
  3. Search for OPENCV_EXTRA_MODULES_PATH in the Search search box, add the path to the modules in the decompressed opencv_contrib, then search and check the OPENCV_ENABLE_NONFREE option.
  4. build_opencv_world can package and compile all opencv libraries together. When configuring the C++ opencv environment later, you do not need to manually select and add each small module. However, this mode is not recommended for specific projects.
  5. For the selection of options related to python, java, js, and tests, use the Search search box to search for "python", "java", "js", and "tests" respectively. Select and cancel relevant options as needed. They are all selected by default. I only need C++ related stuff, so I canceled them all and clicked Configure for the second time.
  6. Search and check the ENABLE_FAST_MATH option and click Configure for the third time.
  7. After Configuring done is displayed, click generate, generating
    done is displayed, cmake compilation is successfully completed, and the OpenCV.sln file is generated when it exists in the output opencv save folder location.

The cmake compilation process will download data from Githup, but the download will generally fail. It is recommended that readers jump to the [Possible Problems] section first to confirm whether they have also failed to download.


VS2019 compilation

  1. Use VS2019 (run as administrator) Open the just compiled project OpenCV.sln, in release|x64 mode, in the solution Resource Manager—>CMakeTargets—>Right-click ALL_BUILD—>Generate.
  2. Also in release|x64 mode, right-click INSTALL–>Generate in the Solution Explorer->CMakeTargets->

    After compilation is completed, the following content will be generated in the install folder of where to build the binaries.

Problems that may arise

Problems that may occur during the cmake compilation process

The problem of Download failed occurred during cmake compilation.

There is CMakeDownloadLog.txt in where to build the binaries. Copy the download link to the browser to download.

Combine it with where is the source code. The contents in the cache folder correspond to each other. The picture below shows that when the download fails, the file size is 0KB. Replace it after the manual download is completed.

Note that the name of the file used for replacement must be consistent with the name of the corresponding empty file.


For some files, you need to replace the webpage by saving it as. Be careful not to copy and paste the webpage content into an empty file. This is invalid.

Process the entire .cache in the same way.

I would like to emphasize that if this kind of problem occurs, you can temporarily complete the CMake compilation process, because each time Configuring will have new download content, and then completely replace the .cache content at once , and finally configure and generate.
The blogger here provides his own [.cache Baidu Cloud, extraction code: ctl6]

Possible problems during the compilation process of VS2019

Usually for some resources, vs2019 does not have administrator operation rights, so you only need to reopen it as an administrator to operate.


Summarize

As simple and detailed as possible, this article introduces the detailed process of compiling the C++ version opencv4.8.0 with source code under Windows 10 in CPU mode.

Guess you like

Origin blog.csdn.net/yangyu0515/article/details/134016497