Skip to main content

Installation Overview

OpenCV can be installed in two ways: using prebuilt binaries or building from source. This guide covers both methods across different platforms.
For most users, especially Python developers, using prebuilt packages (pip, conda, or system package managers) is the quickest way to get started.

Quick Install

For rapid setup, use these package managers:
The opencv-python package includes prebuilt binaries for most platforms and is the easiest way to get started with Python.

Building from Source

Building OpenCV from source gives you full control over features, optimizations, and dependencies.

Prerequisites

1

Install Build Tools

Install a C++ compiler and build tools for your platform:Linux:
Windows:
  • Visual Studio 2015 or later (Community Edition is free)
  • Or MinGW-w64 compiler
macOS:
2

Install CMake

CMake 3.9 or higher is required:
Verify installation:
3

Install Git

Required to download OpenCV source:

Download OpenCV Source

When using both opencv and opencv_contrib, ensure both repositories are at the same version/tag to avoid compatibility issues.

Platform-Specific Build Instructions

Building on Linux

1

Install Dependencies

2

Configure Build

Use cmake -DCMAKE_BUILD_TYPE=Release for optimized builds. Use Debug for development.
3

Compile

4

Install

Installation locations:
  • Binaries: /usr/local/bin
  • Libraries: /usr/local/lib
  • Headers: /usr/local/include/opencv4
  • CMake config: /usr/local/lib/cmake/opencv4

Verify Installation

Configuration Options

Customize your OpenCV build with these CMake options:

Common Options

For a list of all available options, run cmake -L in your build directory after initial configuration.

Language-Specific Setup

Python

Verify Python bindings:

C++

Create a CMakeLists.txt for your project:

Java

Add OpenCV to your Java project:

Troubleshooting

Install missing packages or specify paths manually:
Reduce parallel jobs:
Check installation path:
Add OpenCV to Python path:
Ensure OpenCV bin directory is in PATH:
Copy DLLs to your application directory as a workaround.
If you encounter errors, check the OpenCV forum or GitHub issues for solutions.

Next Steps

Now that OpenCV is installed, you’re ready to write your first computer vision application!

Quickstart Guide

Build your first OpenCV application with step-by-step examples