OpenCV Tutorial
Image Processing
Feature Detection and Description
Drawing Functions
Video Processing
Applications and Projects
Installing OpenCV for Python on Windows is relatively straightforward, especially when using the pip package manager. Here's a step-by-step tutorial to help you set up OpenCV on your Windows system:
Install Python:
Open Command Prompt:
Windows + R
keys together, type in cmd
, and hit Enter
to open the Command Prompt.Update pip (Optional but Recommended):
It's a good idea to have the latest version of pip (the Python package manager) installed. To update pip, run:
python -m pip install --upgrade pip
Install OpenCV using pip:
To install OpenCV, simply run:
pip install opencv-python
This will install the main OpenCV packages.
If you also need the full suite of OpenCV's functionality (like SIFT or SURF methods, which are in the contrib modules), then install the opencv-contrib-python
package:
pip install opencv-contrib-python
Verify Installation:
To ensure that OpenCV was installed correctly, open a new Command Prompt or PowerShell window and type python
to enter the Python REPL (interactive console).
Then, type the following commands:
import cv2 print(cv2.__version__)
If OpenCV was installed correctly, it will display its version number.
Optional - Install an IDE:
Always ensure that the version of OpenCV you're installing is compatible with your Python version. The pip packages are usually well-maintained and kept up-to-date with the latest Python versions.
If you encounter any issues related to dependencies or DLLs when trying to use OpenCV, ensure you have the required Visual C++ redistributable packages installed. They're typically required for Python extensions on Windows, including some functionalities in OpenCV.
With these steps, you should have OpenCV up and running on your Windows machine for Python development.
Python OpenCV setup on Windows with pip:
pip install opencv-python
Sample code for verifying OpenCV installation on Windows:
import cv2 print(cv2.__version__)
Using virtual environments for OpenCV in Python on Windows:
# Create a virtual environment python -m venv myenv # Activate the virtual environment myenv\Scripts\activate # Install OpenCV within the virtual environment pip install opencv-python # Verify installation python -c "import cv2; print(cv2.__version__)" # Deactivate the virtual environment deactivate
Python OpenCV installation with conda on Windows:
conda install -c conda-forge opencv