Install OpenCV-Python in Windows

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
Download and install to default locations:
- Python 3.x (3.4+) from python.org
- Numpy:
pip install numpy - Matplotlib (optional, recommended):
pip install matplotlib
Download latest OpenCV release from GitHub and double-click to extract it.
Go to opencv/build/python/3.x folder.
Copy cv2.pyd to C:/Python3x/lib/site-packages.
Copy the opencv_world.dll file to C:/Python3x/lib/site-packages.
Open Python IDLE and type:
import cv2 as cv
print(cv.__version__)Method 2: Building OpenCV from Source
Download and install Visual Studio and CMake.
Download and install necessary Python packages to their default locations:
- Python
- Numpy
Download OpenCV source from GitHub or SourceForge.
Extract it to a folder and create a new
buildfolder in it.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
Open OpenCV.sln from
opencv/buildfolder with Visual Studio.Set build mode to Release.
Right-click on Solution (or ALL_BUILD) and build it.
Right-click on INSTALL and build it. OpenCV-Python will be installed.
Open Python IDLE and enter
import cv2 as cvto verify the installation.
Hakan Çelik