Tuesday , December 1 2026
Introduction to OpenCV Python Tutorials

Introduction to OpenCV Python Tutorials

Updated: 28 November 2026Level: BeginnerReading time: about 8 minutesOpenCV 4.x

OpenCV (Open Source Computer Vision Library) is the most widely used library for computer vision and image processing. It can read images and video, detect faces and objects, track movement, and much more. This page introduces OpenCV-Python, shows how to install it, and gives you a roadmap of the tutorials in this series.

What You Will Learn

  • What OpenCV and OpenCV-Python are
  • Where OpenCV is used in the real world
  • How to install and test OpenCV
  • How images are stored in OpenCV

Prerequisites

Basic Python: variables, lists, loops and functions. Python 3.8 or newer installed.

What Is OpenCV?

OpenCV is an open-source library written in C++ with more than 2,500 algorithms for image processing, computer vision and machine learning. It was started by Intel in 1999 and is now free for both personal and commercial use. OpenCV-Python is the Python interface to it: you write simple Python code, and the heavy work runs in fast C++ code underneath.

Why OpenCV Works So Well with Python

In OpenCV-Python, every image is a NumPy array. That means you can use all of NumPy, and libraries built on it such as Matplotlib and scikit-learn, directly on images and video frames.

Where Is OpenCV Used?

Area Examples
Security Face detection and recognition, surveillance, intrusion alerts
Traffic Vehicle counting, number plate reading, speed estimation
Retail People counting in malls, shelf monitoring
Industry Automated inspection of products for defects
Healthcare Medical image analysis, X-ray and scan processing
Robotics Navigation, object tracking, gesture control

Install OpenCV

Example
pip install opencv-python

Explanation: This installs the main modules. If you need extra modules such as face recognition (cv2.face), install opencv-contrib-python instead. Do not install both at the same time.

Package Use it when
opencv-python Normal desktop use
opencv-contrib-python You need extra modules like face recognition
opencv-python-headless Servers and Docker, where there is no screen (no imshow)

Test Your Installation

Example
import cv2
print(cv2.__version__)
Output
4.x.x

If a version number prints, OpenCV is ready. The exact number depends on what pip installed.

Your First OpenCV Program

Example
import cv2
img = cv2.imread('machinelearning.png')
print(type(img), img.shape)
cv2.imshow('My first image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Explanation:

  • cv2.imread() loads the image as a NumPy array.
  • img.shape shows (height, width, channels).
  • imshow, waitKey and destroyAllWindows show the image until you press a key.

Learning Path for This Series

Follow the tutorials in this order:

  1. Reading an Image as Color or Grayscale
  2. Extracting RGB Values of a Pixel
  3. Extracting a Region of Interest
  4. Resizing an Image
  5. Rotating an Image
  6. Drawing a Rectangle
  7. Displaying Text on an Image
  8. Color Channels of an Image
  9. Arithmetic Operations on Images
  10. Access Camera and Record Video
  11. Face Detection from an Image, from Webcam, and Face Recognition with Name
  12. Projects: Vehicle Detection and Bus Detection

Common Errors

Problem Cause and fix
ModuleNotFoundError: No module named 'cv2' Install with pip install opencv-python, using the same Python that runs your script (python -m pip install opencv-python).
cv2.imshow error on a server or Colab You have the headless package or no display. Use Matplotlib or google.colab.patches.cv2_imshow.

Interview Questions

Q: What is OpenCV?
An open-source computer vision and image processing library, written in C++ with Python bindings.

Q: How is an image represented in OpenCV-Python?
As a NumPy array of shape (height, width, channels) with dtype uint8, in BGR order.

Summary

OpenCV is the standard library for computer vision. Install it with pip, remember that images are NumPy arrays in BGR order, and follow the learning path above.

Next: Start: Reading an Image

About Machine Learning

Check Also

Image Classification in Python: From SVM to CNN

Image classification with tested scikit-learn models on handwritten digits (SVM 99%), error analysis, the flat-pixel weakness and a Keras CNN for real images.