OpenCV installation on Windows 10
Back to Resources
OPENCV

OpenCV installation on Windows 10

April 5, 2020

OpenCV installation on Windows 10 is more nuanced than on Linux, primarily because Windows lacks a package manager that handles native library dependencies automatically. The choice between using prebuilt binaries from opencv.org and compiling from source determines both the feature set available and the effort required. For most Python-based computer vision work, the prebuilt opencv-python or opencv-contrib-python packages from PyPI are the right starting point. For C++ development or when you need features not included in the prebuilt binaries (CUDA acceleration, GStreamer support, or contrib modules), source compilation is necessary.

The prebuilt binary path is straightforward: download the Windows installer from opencv.org, extract to a directory like C:\opencv, and add C:\opencv\build\x64\vc16\bin (adjust for your Visual Studio version) to the system PATH environment variable. For Python, install opencv-contrib-python via pip to get access to the contributed modules including SIFT, SURF, and ArUco marker detection. The contrib package uses the same import name (import cv2) as the base package, so ensure only one variant is installed in each Python environment.

Source compilation on Windows requires CMake, Visual Studio (2019 or 2022 are current), and optionally the CUDA toolkit if you want GPU acceleration. The CMake configuration step is where you specify build options: OPENCV_EXTRA_MODULES_PATH for contrib modules, WITH_CUDA for NVIDIA GPU support, WITH_GSTREAMER for camera capture, and BUILD_opencv_world to produce a single consolidated DLL rather than per-module DLLs (simplifies deployment). The configuration step downloads additional dependencies (protobuf, eigen, etc.) from GitHub, so a stable internet connection is required.

A common source of confusion on Windows is the Visual Studio runtime version compatibility. OpenCV binaries compiled with VC16 (Visual Studio 2019) are not directly compatible with projects built with VC17 (Visual Studio 2022) due to the CRT ABI, though in practice the binary compatibility between these versions is often sufficient. The safest approach is to compile OpenCV using the same Visual Studio version as your application project, or to use dynamic CRT linking (/MD flag) which relies on the redistributable runtime rather than static linking.

For Python environments, using conda or virtualenv isolates OpenCV installations per project and avoids the DLL conflict issues that arise when multiple OpenCV versions are installed system-wide. The conda-forge channel provides well-maintained OpenCV builds for Windows that include most optional modules. When debugging import errors, the python -c "import cv2; print(cv2.getBuildInformation())" command prints the complete build configuration, confirming which optional modules and backends are available in your installed version.

View original post