- OpenCV is a very extensive computer vision library that offers thousands of algorithms for image analysis and processing.
- En Windows You can work with OpenCV and contrib modules using Pythonpip, .whl files, and distributions like Anaconda.
- Images are managed as NumPy arrays and basic operations such as reading, writing, drawing, and color conversion are applied to them.
- With OpenCV properly installed, you can tackle real-world tasks such as face detection, segmentation, tracking, and augmented reality.
If you've made it this far, it's because you want to install OpenCV with all its contrib modules on Windows , and you've probably already realized it's not as simple as just running a command and being done. Between Python versions, complementary libraries, package managers, and compilation options, it's very easy to get lost along the way.
In the following lines, you'll find a meticulously crafted, step-by-step guide in Spanish (Spain) that combines the two main ways to work with OpenCV on Windows : using pre-compiled packages (pip, whl, and Anaconda) and understanding what it means to work with the library compiled from code and with contrib modules. We'll also review key computer vision concepts that will help you truly get the most out of everything you install.
What is OpenCV and why are the contributor modules of interest?
Before touching anything on your machine, it's important to understand what you're installing. OpenCV (Open Source Computer Vision) is a vast computer vision and image processing library, originally developed by Intel and now maintained by a huge community. It includes over 2500 algorithms for tasks as varied as face detection, object recognition, motion tracking, segmentation, camera calibration, and augmented reality.
OpenCV is available for multiple languages and systems : C++, Python, Java, as well as for Windows, macOS, and Linux . In our case, we will focus on OpenCV-Python , which is the specific binding (API) for working from Python and integrates very well with libraries like NumPy or Matplotlib , essential for any serious computer vision work.
When we talk about "contrib," we're referring to an additional set of experimental or advanced modules that aren't part of the core OpenCV library. These contrib modules extend the library with more modern or specialized algorithms, and that's exactly what you need if you want extra functionality without having to go through the entire compilation process from scratch.
In Python, the most direct way to get that extra functionality is to use packages like opencv-contrib-python or opencv-contrib-python-headless , which are precompiled binaries with the contrib modules already integrated. They aren't the "official" OpenCV.org packages, but they save a huge amount of time and are more than sufficient for most projects.
Prerequisites: Python, NumPy, Matplotlib, and related software
To work comfortably with OpenCV, you need a basic foundation in a scientific Python environment on your system. Specifically, you'll be using Python 3 (no Python 2 at this point), and you'll almost always find it helpful to have libraries like NumPy, SciPy, and Matplotlib , as well as Jupyter or an IDE like Sublime Text, VS Code, or similar.
There are two main ways to set up this environment on Windows: install Python "straight up" from its official website and manage everything with pip , or use a distribution like Anaconda that installs Python, the most used scientific packages and its own environment management ecosystem all at once.
If you choose the traditional method, you'll need to download the 32-bit or 64-bit Windows installer from the official Python website , depending on your system. Once downloaded, it's essential to check the "Add Python 3.x to PATH" box , as this will allow you to launch Python from any console simply by typing `python` without having to manually specify long paths.
Additionally, you must ensure that pip, the Python package manager , is included in that installation. Pip will be your greatest ally for installing OpenCV and the other dependencies, because with a couple of commands you can accomplish in seconds what could take hours to do manually.
Installing Python on Windows: the classic method and with Anaconda
On Windows, you have two reasonable ways to set up your Python environment and then add OpenCV and the contrib modules: a direct download from python.org or using the Anaconda distribution . Both paths will lead you to the same destination, but each has its practical advantages.
If you choose the python.org path, after downloading the executable for the desired version (for example, Python 3.8.x or 3.10.x, whichever is most readily available), simply run it as administrator, check the box to add it to your PATH, leave the option to install pip enabled , and complete the wizard. Afterward, you can open the Start menu, search for "Python 3.x," and verify that the interactive console launches without errors.
To finish verifying, open a Command Prompt ( cmd ) and type:
python -V
If everything is correct, you'll see the installed Python version. You can then check pip with:
pip -V
If you want to fine-tune the versions , you can also update pip with:
python -m pip install -U pip
The other option is to use Anaconda , a distribution geared towards data processing, science, and machine learning that simplifies much of the dependency management. Download the installer from its official website, choose the Windows version (32-bit or 64-bit, depending on your system), follow the wizard, and you'll have Python, NumPy, SciPy, Matplotlib, Jupyter, and pip ready to use.
With Anaconda, to verify that everything is in place, open a console (it could be the "Anaconda Prompt") and run the same checks: python -V and pip -V . You will see something like Python 3.x Anaconda 4.x, confirming that your environment is operational and ready to install OpenCV.
Ways to install OpenCV compiled with contrib on Windows
Once you have Python properly installed, we can delve into OpenCV. On Windows, the practical way to get OpenCV compiled with contrib modules without struggling with CMake and Visual Studio is to use pre-compiled binary packages . You can do this primarily in two ways: using pip with PyPI packages or by installing a .whl file downloaded from a binary repository.
The most direct way using pip is:
- pip install opencv-python: installs the “core” modules, that is, the main part of OpenCV.
- pip install opencv-contrib-python: installs both the main and additional contrib modules.
- pip install opencv-python-headless: only main modules, but without GUI support (no display windows).
- pip install opencv-contrib-python-headless: main modules + contributors, also without a graphical interface.
These packages don't come directly from OpenCV.org, but from an external maintainer; however, they are widely used and thoroughly tested . Most users typically install opencv-contrib-python , as it provides all the essential components plus extras without requiring any manual compilation.
A classic alternative, especially useful if you need a very specific version combination (for example, OpenCV 3.2 with Python 3.6 on a 64-bit system), is to download a pre-compiled .whl (wheel) file for your system. This page usually lists several files with names indicating the OpenCV version, the Python version, and the architecture (win32 or amd64), and some include "+contrib" in the name, indicating that they have the contrib modules included.
The process would be something like this:
pip install "D:\opencv\opencv_python-3.2.0+contrib-cp36-cp36m-win_amd64.whl"
You adjust the path to the location where you saved the file and run the command in the console. If there are no version conflicts, pip will install the wheel, and at the end you will see a message confirming that OpenCV with contrib has been successfully installed for your Python version.
Quick installation with pip: opencv-contrib-python
For most projects, especially if you're just starting out or want to get straight to the point, all you need is Python 3 running, pip working, and to launch from the command prompt or Anaconda Prompt:
pip install opencv-contrib-python
With that single command, the latest compatible version of OpenCV 4.x, including the contrib modules and all necessary dependencies, will be downloaded from PyPI. It's an unofficial but extremely convenient method, saving you the trouble of compiling OpenCV from source code on your own machine.
Once the process is complete, you can test that the installation was successful by opening Python (from the console or any IDE) and importing the library:
import cv2
print(cv2.__version__)
If no errors appear and a version number is printed (for example, 4.2.0 or higher), it means that OpenCV is installed and accessible from your Python interpreter . It's a quick but very useful check to avoid surprises later when running your scripts.
It's important to note a key licensing detail: the opencv-python and opencv-contrib-python packages do not include "non-free" algorithms like SIFT or SURF in their classic, proprietary versions, precisely because they cannot be distributed as such for legal reasons. If you need those exact algorithms, you will have to compile OpenCV yourself from source code, enabling the relevant options, or use free alternatives that implement similar functionality.
If you want to further reduce dependencies (for example, on a server where displaying windows isn't necessary), you can opt for the headless variant , which omits everything related to the GUI. The rest of the library's usage will be identical, except that you won't be able to use functions like cv2.imshow to open image windows.
Testing OpenCV: First scripts and checks
Once OpenCV is installed, the next step is to ensure you can actually load and work with images without errors . A minimal test is to create a simple Python file, for example, test-opencv.py , with something as basic as:
import cv2
imagen = cv2.imread("logo.jpg")
cv2.imshow("prueba", imagen)
cv2.waitKey(0)
Save this script in the same folder where you have a test image called logo.jpg , open a console, navigate to that folder and run:
python prueba-opencv.py
If a window opens displaying the image without errors in the console, you can consider the installation successful. You are using OpenCV's basic image reading and viewing functions , so if this works, the more advanced operations should also work.
Another common step is to double-check the version from within the script itself to ensure you're using the correct one. Simply add:
print("Versión de OpenCV:", cv2.__version__)
When you run the program, you'll see the version number in the console , which helps you confirm that you're not inadvertently launching a different installation (for example, if you have multiple Anaconda environments or multiple versions of Python on your system).
Images as matrices: how OpenCV sees your data
To take full advantage of OpenCV, it's crucial to understand that a digital image is simply a matrix of pixels . OpenCV, through Python, represents images as NumPy arrays , meaning you can apply vector operations, transformations, and filters very efficiently.
In an image, each pixel is a small "block" of information containing numerical values. The more pixels an image has (higher resolution), the more detail it can process . In addition to width and height, an image has a color depth defined by the bits per pixel (bpp). The number of possible tones is given by the expression:
number of colors = 2^bpp
For example, in a binary image with 1 bit per pixel, there are only two options: 0 usually represents black and 1 represents white. In a grayscale image with 8 bits per pixel, you have 256 levels , where 0 is black, 255 is white, and the rest are intermediate shades of gray.
Standard color images use three channels: red, green, and blue . However, OpenCV stores images in BGR (Blue, Green, Red) format by default , while libraries like Matplotlib expect RGB images. This results in the classic bluish tint effect when displaying an image read from OpenCV with Matplotlib without converting the channels.
To solve this, a color conversion is usually performed using cv2.cvtColor , swapping the B and R channels before displaying the image with Matplotlib. This way, the colors appear as expected, and you avoid that strange color cast that can be quite confusing at first.
Basic image operations in OpenCV
Once you understand that an image is a matrix, the first operations you'll perform with OpenCV are usually very simple: opening, saving, and drawing on images . These initial steps help you become familiar with the API before delving into more advanced analysis.
To read an image from disk, use `cv2.imread` , while to display it in a window, use `cv2.imshow` . When you want to save an image (for example, the result of processing), use `cv2.imwrite` , specifying the output filename and the array of the modified image.
If you're interested in drawing simple shapes (lines, rectangles, circles) on an image, OpenCV offers dedicated and very straightforward functions. These typically require certain common parameters: the image you're drawing on, the coordinates or key points, the color as a BGR tuple (for example, (255, 0, 0) for pure blue in BGR), and the line thickness .
For example, to draw a straight line, you need to specify the two endpoints of the line . For a rectangle, you must pass the coordinates of the top-left and bottom-right corners. In the case of a circle, you specify the center and the radius. These functions are perfect for creating masks, overlays, or detection visualizations (for example, boxes around faces or objects).
Similarly, adding text over an image is done with another specific function that takes the string to be written, the starting position (the text starts from the bottom left corner of the point you pass over), the font type and size, and attributes such as color, thickness, and line type. ` lineType = cv2.LINE_AA` is often used to give the letters an anti-aliased look.
Using IDEs and development environments: Jupyter, Sublime Text, and Anaconda
Although you can work with OpenCV by writing scripts in Notepad, in practice it's much more convenient to use an IDE or interactive environment . Two common options when starting out with computer vision in Python are Jupyter Notebook and Sublime Text with the Anaconda package.
Jupyter is incredibly useful for testing code snippets, viewing inline images, and documenting your experiments almost like writing a lab notebook. You can run cells, visualize the results, and change parameters on the fly—perfect when working with filters, thresholds, or detectors you want to fine-tune.
Sublime Text, on the other hand, is a lightweight yet powerful text editor, ideal if you prefer a more ".py file + console" workflow. To get the most out of it when programming in Python, it's advisable to install the Sublime package manager and then the Anaconda package (the one from Sublime, not the Python distribution), which adds autocompletion, linting, and tools specifically for Python development.
The process is usually as follows: first, install Sublime Text 3 from its official website; then, activate the package manager by pasting the script provided by the Package Control page into the Sublime console; and finally, install the "Anaconda" package from the Package Control menu. This transforms Sublime into a fairly complete environment for programming with Python and OpenCV.
On systems where you already use the Anaconda Python distribution, you can combine both: create an Anaconda environment with the version of Python and OpenCV you want and configure Sublime to launch your scripts using that specific interpreter, so that each project can have its dependencies well isolated.
What can you do with OpenCV once it's installed?
With OpenCV fully operational (and even better if you have the contrib modules installed), the possibilities on Windows are enormous. One of the best-known applications is face and object detection , which is used in photography (autofocus, filters), marketing (audience analysis), and security systems.
You can also use OpenCV to segment images and count objects , detect motion in video, extract features from scenes to feed machine learning models, track points of interest, or build simple marker-based augmented reality systems.
Mastering OpenCV involves a lot of practice with simple image processing operations (opening, cropping, resizing, converting to grayscale, applying filters, drawing overlays) and a solid understanding of how these operations combine to build more complex pipelines. With a solid foundation, moving on to advanced techniques becomes much easier.
The official OpenCV documentation, along with tutorials and community forums, is a virtually endless resource. But it all starts with what you just saw: having the library properly installed, with the correct version of Python and the necessary contrib modules . Once you've overcome that first hurdle, the only limit is your desire to experiment with images and videos.
After going through this whole process—choosing between classic installation or with Anaconda, deciding whether to use pip or wheels to have OpenCV compiled with contrib, checking the version and testing basic image reading and drawing scripts—you now have a solid foundation to start seriously experimenting with computer vision on Windows; from here, each new project will be the perfect excuse to explore this library a little more and continue expanding your Python toolbox.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.