Windows Static OpenCV Build
The Windows build also needs a static OpenCV package. The flow mirrors the macOS setup with a few Windows-specific tweaks.
1. Download OpenCV
wget -O opencv.zip https://github.com/opencv/opencv/archive/refs/tags/4.11.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.11.0.zip
unzip opencv.zip
unzip opencv_contrib.zipCreate a build folder that will hold the OpenCV build output:
mkdir build
cd build2. Install vcpkg and the OpenCV dependencies
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat.\vcpkg.exe install libpng:x64-windows-static libjpeg-turbo:x64-windows-static tiff:x64-windows-static openblas:x64-windows-static-release3. Build OpenCV
Go back to the parent directory and enter the build folder.
Specify DCMAKE_INSTALL_PREFIX to point at the destination folder for OpenCV, and set DCMAKE_TOOLCHAIN_FILE to the cmake toolchain file inside the vcpkg repo you just cloned.
cmake `
-DCMAKE_BUILD_TYPE=Release `
-DBUILD_SHARED_LIBS=OFF `
-DWITH_OPENBLAS=ON `
-DWITH_ACCELERATE=OFF `
-DWITH_TEGRA=OFF `
-DCMAKE_INSTALL_PREFIX="F:/opencv/install" `
-DBUILD_DOCS=OFF `
-DBUILD_EXAMPLES=OFF `
-DBUILD_TESTS=OFF `
-DBUILD_PERF_TESTS=OFF `
-DWITH_PNG=ON `
-DWITH_JPEG=ON `
-DWITH_TIFF=ON `
-DWITH_WEBP=OFF `
-DWITH_OPENJPEG=OFF `
-DWITH_JASPER=OFF `
-DWITH_OPENEXR=OFF `
-DWITH_V4L=OFF `
-DWITH_FFMPEG=OFF `
-DWITH_PROTOBUF=ON `
-DWITH_IPP=OFF `
-DWITH_OPENCL=OFF `
-DWITH_CAROTENE=OFF `
-DBUILD_opencv_java=OFF `
-DBUILD_opencv_python=OFF `
-DCMAKE_TOOLCHAIN_FILE="F:/rust/vcpkg/scripts/buildsystems/vcpkg.cmake" `
-DOPENCV_EXTRA_MODULES_PATH="../opencv_contrib-4.11.0/modules" `
../opencv-4.11.0Build and install:
cmake --build . --target install --config Release --parallel 8
cmake --install . --prefix F:/opencv/install4. Build your own application
Set the environment variables:
$env:OPENCV_LINK_LIBS="opencv_core4110,opencv_imgcodecs4110,opencv_imgproc4110,opencv_dnn4110,ittnotify,zlib,libjpeg,libpng,libtiff,libprotobuf"
$env:OPENCV_LINK_PATHS="F:/opencv/install/x64/vc17/staticlib"
$env:OPENCV_INCLUDE_PATHS="F:/opencv/install/include"
$env:OPENCV_MSVC_CRT="static"Then compile your project:
cargo build --releaseLast updated on: