Table of Contents
In this tutorial, you will learn how to install OpenCV on Windows. This includes a complete guide to installation using prebuilt binaries.
After completing this blog post, you will be able to install OpenCV on your Windows machine on your own. You will also be able to choose the method that will suit you the best.
To learn how to Install OpenCV on Windows, just keep reading.
Installing OpenCV on Windows
Hello and welcome to today’s tutorial. If you are here, I assume you must have a Windows computer or need to use one for Computer Vision. First, let me assure you of a doubt you might have nurtured.
Yes, it is possible to practice Deep Learning and Computer Vision on a Windows machine. We at PyImageSearch are firm believers in democratizing learning.
You do not need an expensive laptop to get started with OpenCV.
In this tutorial, we will guide you through the various ways you can follow to get OpenCV installed on your Windows computer.
Installing OpenCV Using Pip
Installing OpenCV Python using pip is fairly easy. However, there are a few things to keep in mind before we get started.
- This is a prebuilt CPU-only OpenCV package for Python. You cannot follow these steps if you are on a GPU-powered computer.
- These are unofficial prebuilt packages for installing OpenCV. They are not official OpenCV packages released by the OpenCV.org team.
- It is essential to have Python and pip installed on your Windows machine before you get started. If you do not have Python installed, please download and install the latest version from here.
With all the disclaimers and prerequisites done, let’s get started with some installation. Here are four OpenCV packages that are pip-installable on the PyPI repository:
- opencv-python: This repository contains just the main modules of the OpenCV library. If you’re a PyImageSearch reader, you do not want to install this package.
- opencv-contrib-python: The opencv-contrib-python repository contains both the main modules along with the contrib modules. This is the library we recommend you install, as it includes all OpenCV functionality.
- opencv-python-headless: Same as opencv-python but no GUI functionality. Useful for headless systems.
- opencv-contrib-python-headless: Same as opencv-contrib-python but no GUI functionality. Useful for headless systems.
You DO NOT want to install both opencv-python and opencv-contrib-python. Pick ONE of them.
Step 1: Make sure you have python and pip installed. Pip version 19.3 is the minimum supported version. This means a pip with a version higher than 19.3 is required.
To check the pip version, open your command prompt and type:
$ pip -V
This will let you know the version of pip you are using. To upgrade pip to the latest version type:
$ pip install --upgrade pip
Step 2 (optional): Create a virtual environment and install OpenCV there. Creating a virtual environment in Python is a very good practice, and we highly recommend it.
You can develop multiple projects without worrying if your libraries are going to crash with each other. This can be achieved through virtualenv
and virtualenvwrapper
as well as Anaconda. In this tutorial, we will use virtualenv
and virtualenvwrapper
.
$ pip install virtualenv virtualenvwrapper $ pip install virtualenvwrapper-win
You’ll see some terminal output that sets up virtualenvwrapper
. You now have access to new terminal commands:
- Create an environment with
mkvirtualenv
. - Activate an environment (or switch to a different one) with
workon
. - Deactivate an environment with
deactivate
. - Remove an environment with
rmvirtualenv
.
Read the documentation to get familiar with the commands.
Next, create a virtual environment called cv
(you can name it anything you want) to install OpenCV.
$ mkvirtualenv cv -p python3
Switch to this environment using:
$ workon cv
Step 3: With everything taken care of, we finally start installing OpenCV on your Windows system.
$ pip install opencv-contrib-python
To check if OpenCV is installed properly, open a new command prompt and enter a Python shell using the following command:
$ python >> import cv2 >> print(cv2.__version__)
And that’s it. OpenCV is successfully installed on your windows machine. You are ready to embark on your Computer Vision journey.
We recommend you go through some of our tutorials on OpenCV fundamentals to get yourself acquainted with the topic.
Having Problems Configuring Your Development Environment?
All that said, are you:
- Short on time?
- Learning on your employer’s administratively locked system?
- Wanting to skip the hassle of fighting with the command line, package managers, and virtual environments?
- Ready to run the code right now on your Windows, macOS, or Linux system?
Then join PyImageSearch University today!
Gain access to Jupyter Notebooks for this tutorial and other PyImageSearch guides that are pre-configured to run on Google Colab’s ecosystem right in your web browser! No installation required.
And best of all, these Jupyter Notebooks will run on Windows, macOS, and Linux!
What's next? We recommend PyImageSearch University.
86 total classes • 115+ hours of on-demand code walkthrough videos • Last updated: October 2024
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled
I strongly believe that if you had the right teacher you could master computer vision and deep learning.
Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?
That’s not the case.
All you need to master computer vision and deep learning is for someone to explain things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to change education and how complex Artificial Intelligence topics are taught.
If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to successfully and confidently apply computer vision to your work, research, and projects. Join me in computer vision mastery.
Inside PyImageSearch University you'll find:
- ✓ 86 courses on essential computer vision, deep learning, and OpenCV topics
- ✓ 86 Certificates of Completion
- ✓ 115+ hours of on-demand video
- ✓ Brand new courses released regularly, ensuring you can keep up with state-of-the-art techniques
- ✓ Pre-configured Jupyter Notebooks in Google Colab
- ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
- ✓ Access to centralized code repos for all 540+ tutorials on PyImageSearch
- ✓ Easy one-click downloads for code, datasets, pre-trained models, etc.
- ✓ Access on mobile, laptop, desktop, etc.
Summary
In this tutorial, we learned how to install OpenCV from prebuilt binaries. We also learned which package to install and how to create a virtual environment for working on the package. For all purposes of learning computer vision using Python, we highly recommend installing opencv-contrib-python using prebuilt binaries.
If you are looking to start your development journey in computer vision, check out some of our tutorials on OpenCV.
Happy learning 🙂
References
- PyImageSearch: Pip Install OpenCV guide
- Adam Hacks: Installing OpenCV on Windows
- PyPi: Pip install OpenCV
Citation Information
Raha, R. “Installing OpenCV on Windows,” PyImageSearch, D. Chakraborty, P. Chugh, A. R. Gosthipaty, S. Huot, K. Kidriavsteva, and A. Thanki, 2022, https://pyimg.co/b3q05
@incollection{Raha_2022_Installing-OpenCV-Windows, author = {Ritwik Raha}, title = {Installing {OpenCV} on {W}indows}, Booktitle = {PyImageSearch}, editor = {Devjyoti Chakraborty and Puneet Chugh and Aritra Roy Gosthipaty and Susan Huot and Kseniia Kidriavsteva and and Abhishek Thanki}, year = {2022}, note = {https://pyimg.co/b3q05}, }
Unleash the potential of computer vision with Roboflow - Free!
- Step into the realm of the future by signing up or logging into your Roboflow account. Unlock a wealth of innovative dataset libraries and revolutionize your computer vision operations.
- Jumpstart your journey by choosing from our broad array of datasets, or benefit from PyimageSearch’s comprehensive library, crafted to cater to a wide range of requirements.
- Transfer your data to Roboflow in any of the 40+ compatible formats. Leverage cutting-edge model architectures for training, and deploy seamlessly across diverse platforms, including API, NVIDIA, browser, iOS, and beyond. Integrate our platform effortlessly with your applications or your favorite third-party tools.
- Equip yourself with the ability to train a potent computer vision model in a mere afternoon. With a few images, you can import data from any source via API, annotate images using our superior cloud-hosted tool, kickstart model training with a single click, and deploy the model via a hosted API endpoint. Tailor your process by opting for a code-centric approach, leveraging our intuitive, cloud-based UI, or combining both to fit your unique needs.
- Embark on your journey today with absolutely no credit card required. Step into the future with Roboflow.
Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF
Enter your email address below to join the PyImageSearch Newsletter and download my FREE 17-page Resource Guide PDF on Computer Vision, OpenCV, and Deep Learning.
Comment section
Hey, Adrian Rosebrock here, author and creator of PyImageSearch. While I love hearing from readers, a couple years ago I made the tough decision to no longer offer 1:1 help over blog post comments.
At the time I was receiving 200+ emails per day and another 100+ blog post comments. I simply did not have the time to moderate and respond to them all, and the sheer volume of requests was taking a toll on me.
Instead, my goal is to do the most good for the computer vision, deep learning, and OpenCV community at large by focusing my time on authoring high-quality blog posts, tutorials, and books/courses.
If you need help learning computer vision and deep learning, I suggest you refer to my full catalog of books and courses — they have helped tens of thousands of developers, students, and researchers just like yourself learn Computer Vision, Deep Learning, and OpenCV.
Click here to browse my full catalog.