Skip to main content
OpenCV provides full support for Windows platforms with Visual Studio, MinGW, and other compilers. Pre-built binaries are also available for quick setup.

Quick Start with Pre-built Libraries

The fastest way to get started with OpenCV on Windows:
1

Download Pre-built Package

Download the Windows installer from the OpenCV releases page:
Pre-built packages include binaries for Visual Studio 2015-2022 (x86 and x64).
2

Extract Archive

Run the self-extracting archive. It will create a directory structure:
3

Set Environment Variables

Add OpenCV to your system path:
Restart your terminal or IDE after setting environment variables.

Building from Source

For the latest features or custom configurations, build OpenCV from source.

Prerequisites

Required:Optional:

Build Steps with Visual Studio

1

Clone Repository

Open Git Bash or Command Prompt:
Or download and extract a release archive.
2

Create Build Directory

3

Configure with CMake GUI

Launch CMake GUI:
  1. Set Source code to: C:/opencv
  2. Set Build binaries to: C:/opencv/build
  3. Click Configure
  4. Select your Visual Studio version and platform (x64 recommended)
  5. Click Finish
Enable “Grouped” view for easier navigation of CMake options.
4

Adjust Build Options

Key CMake options to consider:
Click Configure again after changes.
5

Generate Project Files

Once configuration completes without errors:
  1. Click Generate
  2. Click Open Project to launch Visual Studio
6

Build in Visual Studio

In Visual Studio:
  1. Select Release configuration (or Debug)
  2. Right-click ALL_BUILD project → Build
  3. Wait for compilation (15-60 minutes depending on options)
Build both Release and Debug configurations if you need both.
7

Install (Optional)

Right-click INSTALL project → BuildThis copies files to the install directory (default: C:/Program Files/opencv).

Build Steps with Command Line

For automated builds or CI/CD pipelines:

Using Git Bash for Automated Build

A complete build script using Git Bash:

Building with opencv_contrib

To include extra modules from opencv_contrib:

Optional Dependencies

Intel Threading Building Blocks (TBB)

For improved parallel processing performance:
  1. Download TBB from Intel oneAPI
  2. Extract to C:\opencv\dep\tbb
  3. Add CMake option: -DWITH_TBB=ON -DTBB_DIR=C:/opencv/dep/tbb

CUDA (NVIDIA GPU Acceleration)

1

Install CUDA Toolkit

Download from NVIDIA CUDA DownloadsInstall with default options.
2

Configure OpenCV with CUDA

Set CUDA_ARCH_BIN to match your GPU’s compute capability. Build time increases significantly with CUDA enabled.

Python Support

Build Configuration Options

Minimal Build for Distribution

Setting Up Your Development Environment

Using OpenCV in Visual Studio Projects

1

Set Environment Variable

2

Add to System PATH

Or manually add C:\opencv\build\x64\vc17\bin to System PATH via Control Panel.
3

Configure Your Project

In your project’s CMakeLists.txt:
Or manually configure Include Directories and Library Directories in Visual Studio project properties.

Verification

Test your OpenCV installation:

Package Manager Installation

vcpkg

For dependency management:

Conan

Troubleshooting

  • Ensure Visual Studio is installed with C++ tools
  • Use “Developer Command Prompt for VS” to run CMake
  • Specify generator explicitly: -G "Visual Studio 17 2022"
Add OpenCV bin directory to PATH:
Or copy DLL files next to your executable.
  • Verify NumPy is installed: pip install numpy
  • Check Python version matches (32/64-bit)
  • Verify cv2.pyd is in Python’s site-packages
  • Try rebuilding with correct Python paths
  • Ensure CUDA Toolkit version matches VS version compatibility
  • Update GPU drivers
  • Reduce CUDA_ARCH_BIN to only your GPU’s compute capability

Next Steps

Visual Studio Integration

Set up OpenCV in Visual Studio projects

CMake Configuration

Explore all configuration options

Getting Started

Write your first OpenCV application

Python Bindings

Use OpenCV with Python