· Hakan Çelik · OpenCV / Setup · 1 dk okuma

Install OpenCV-Python in Windows

Learn to setup OpenCV-Python in Windows. Covers quick installation from prebuilt binaries and building from source using CMake and Visual Studio.

Install OpenCV-Python in Windows

Note: Please prefer binaries distributed with PyPI, if possible. See Install OpenCV with pip for details.

Goals

We will learn to setup OpenCV-Python in your Windows system.

Method 1: Installing from Prebuilt Binaries

  1. Download and install to default locations:

    • Python 3.x (3.4+) from python.org
    • Numpy: pip install numpy
    • Matplotlib (optional, recommended): pip install matplotlib
  2. Download latest OpenCV release from GitHub and double-click to extract it.

  3. Go to opencv/build/python/3.x folder.

  4. Copy cv2.pyd to C:/Python3x/lib/site-packages.

  5. Copy the opencv_world.dll file to C:/Python3x/lib/site-packages.

  6. Open Python IDLE and type:

import cv2 as cv
print(cv.__version__)

Method 2: Building OpenCV from Source

  1. Download and install Visual Studio and CMake.

  2. Download and install necessary Python packages to their default locations:

    • Python
    • Numpy
  3. Download OpenCV source from GitHub or SourceForge.

  4. Extract it to a folder and create a new build folder in it.

  5. Open CMake-gui (Start > All Programs > CMake-gui):

    • Click Browse Source… and locate the opencv folder
    • Click Browse Build… and locate the build folder
    • Click Configure and choose your compiler
    • Configure the WITH, BUILD, and ENABLE fields
    • Click Generate
  6. Open OpenCV.sln from opencv/build folder with Visual Studio.

  7. Set build mode to Release.

  8. Right-click on Solution (or ALL_BUILD) and build it.

  9. Right-click on INSTALL and build it. OpenCV-Python will be installed.

  10. Open Python IDLE and enter import cv2 as cv to verify the installation.


Source: OpenCV Python Tutorials — Original Documentation

Back to Blog

Related Posts

View All Posts »
Install OpenCV-Python in Fedora

Install OpenCV-Python in Fedora

OpenCV · 2 dk

Learn to setup OpenCV-Python in Fedora using pre-built binaries or building from source. Includes CMake configuration, GCC setup, optional dependencies like TBB and Eigen.

Install OpenCV-Python in Ubuntu

Install OpenCV-Python in Ubuntu

OpenCV · 2 dk

Learn to setup OpenCV-Python in Ubuntu using two methods: installing from pre-built binaries or compiling from source. Step-by-step guide tested on Ubuntu 16.04 and 18.04.

Install OpenCV for Python with pip

Install OpenCV for Python with pip

OpenCV · 2 dk

The recommended way for most users to get OpenCV in Python: install from PyPI with pip. Covers virtual environments, platform notes, PyPI package variants, and common troubleshooting.

How OpenCV-Python Bindings Work

How OpenCV-Python Bindings Work

OpenCV · 3 dk

Learn how OpenCV-Python bindings are generated from C++ headers. We cover CV_EXPORTS_W, CV_WRAP, and other macros, plus the gen2.py generator and hdr_parser.py header parser scripts.