官方代码https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-visual-studio-community-2017
编译工具
visual studio 2017
一、编译protobuf
1、下载protobuf
protobuf-3.11.2:https://github.com/google/protobuf/archive/v3.11.2.zip
2、解压
解压至:D:\protobuf-3.11.2
3、编译
打开windows powershell
mkdir protobuf_build
cd protobuf_build
cmake -A x64 -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
cmake --build . --config Release -j 2
cmake --build . --config Release --target install
Vulkan SDK用于调用GPU,这里不多赘述
二、编译opencv
1、下载cmake
官网链接:Download | CMake
2、下载opencv和opencv_contrib
opencv:Release OpenCV 4.8.0 · opencv/opencv · GitHub
opencv_contrib:Tags · opencv/opencv_contrib · GitHub
安装好后放到设定文件夹,如,
3、使用cmake编译opencv
source code:D:\opencv\opencv-4.8.0\sources
build the binaries:D:\opencv\tools
设定好后点击configure,随后选择vs版本以及操作系统,点击finish
第一次configure后会出现如下情况,
在红色区域找到“OPENCV_EXTRA_MODULES_PATH”,输入:D:\opencv\opencv_contrib-4.8.0\modules,以安装对应版本的扩展包
如果要生成生成opencv_world.lib,则勾选“BUILD_opencv_world”
再次configure,红色区域会消失,
随后generate,
接下来便可在D:\opencv\tools下找到并打开opencv的解决方案:D:\opencv\tools\OpenCV.sln
右键解决方案->生成解决方案,右键cmaketargets的install->仅用于项目->仅生成INSTALL
三、编译ncnn
下载源码:GitHub - Tencent/ncnn: ncnn is a high-performance neural network inference framework optimized for the mobile platform
解压至D盘,如:D:\ncnn
cd D:\ncnn
mkdir -p protobuf_build
cd protobuf_build
开始编译ncnn,
## 注意把<protobuf-root-dir>换成你的protobuf的目录,如:D:/protobuf-3.11.2
## DNCNN_VULKAN设成OFF
## 指定DOpenCV_DIR的路径,如:D:/opencv/tools
cmake -A x64 -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=D:/protobuf-3.11.2/protobuf_build/install/include -DProtobuf_LIBRARIES=D:/protobuf-3.11.2/protobuf_build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=D:/protobuf-3.11.2/protobuf_build/install/bin/protoc.exe -DNCNN_VULKAN=OFF .. -DOpenCV_DIR=D:/opencv/tools
cmake --build . --config Release -j 2
cmake --build . --config Release --target install
至此,完成了在windows上对ncnn的编译