Algorithm Deployment Series Article Directory
Article Directory
foreword
Record the process of configuring the OpenCV + NCNN deployment environment on the Windows 10 system. The following is a detailed record of the compilation process of OpenCV and NCNN
1. Compile OpenCV4.x version with opencv_contrib4.x
1. Install cmake
Cmake download link , select the ZIP package of the version you want and decompress it
Start cmake-gui.exe in the cmake\bin directory
2. Install protobuf (take version 3.4.0 as an example)
Download protobuf-3.4.0 from https://github.com/google/protobuf/archive/v3.4.0.zip, unzip it to the specified directory
, open the VS2015 command line tool, and use the following command to compile
cd <protobuf-root-dir>
mkdir build
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
or
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
nmake
nmake install
3. OpenCV compilation
opencv4.5.1
opencv_contrib4.5.1
To compile OpenCV, you need to download some extra files, but they cannot be downloaded from the domestic Internet. Here is the .cache folder of the opencv4.5.1 version downloaded by netizens. You can pick it up yourself: download link password: 7beq, and put the .cache directly after downloading Mainly modify the following points in the root directory of opencv
:
Check the computing power of your N card graphics website : https://developer.nvidia.com/cuda-gpus
勾选: with_cuda、OPENCV_ENABLE_NONFREE、BUILD_opencv_world、可选:OPENCV_DNN_CUDA
不勾选:build_java、build_tests、with vtk、BUILD_opencv_python_tests、BUILD_opencv_python_bindings_generator
You can click Configure several times until there is no red, and then click 2-3.
Right-click ALL_BUILD to generate, wait for 2 hours to see 0 failures, right-click INSTALL to generate , after the compilation is completed, there will be compiled opencv in build\install
Two, compile NCNN
1. Download and install vulkan (required to call the graphics card)
Download the latest version of vulkan from https://vulkan.lunarg.com/sdk/home and install it to the specified directory
- Configure environment variables (optional), an example is as follows: 1.1.106.0
- Vulkan_INCLUDE_DIR = C:\VulkanSDK\1.1.106.0\Include
- Vulkan_LIBRARY = C:\VulkanSDK\1.1.106.0\Lib
- VULKAN_SDK = C:\VulkanSDK\1.1.106.0
- Install the vulkan_NVIDIA driver https://developer.nvidia.com/vulkan-driver. Simple installation is enough.
2. Download the ncnn-full file
ncnn-full-20220709 version download link
3. Start compiling
Open the VS2015 command line tool and use the following command to compile
cd ncnn
mkdir -p build
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=E:/protobuf-3.4.0/build_vs2017/install/include -DProtobuf_LIBRARIES=E:/protobuf-3.4.0/build_vs2017/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=E:/protobuf-3.4.0/build_vs2017/install/bin/protoc.exe -DNCNN_VULKAN=ON -DOpenCV_DIR=E:/opencv/build ..
or
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=<protobuf-build-dir>/install/include -DProtobuf_LIBRARIES=<protobuf-build-dir>/install/lib/libprotobufd.lib -DProtobuf_PROTOC_EXECUTABLE=<protobuf-build-dir>/install/bin/protoc.exe -DNCNN_VULKAN=ON -DOpenCV_DIR=E:/opencv/build ..
nmake
nmake install