Skip to content
47 / Answers

OpenCV for pixels, MediaPipe for people.

OpenCV is the open-source library every vision project touches: reading cameras and files, resizing, filtering, drawing, geometry, and running neural models. MediaPipe is Google's toolkit of ready-trained, on-device models for hands, faces, poses and more, with a Python API that works in minutes. Learn OpenCV for fundamentals; reach for MediaPipe when you need a person tracked today.

OpenCV
Image and video processing, since 2000, C++ with Python bindings
MediaPipe
Pretrained on-device models: hands, face, pose, objects
Install
pip install opencv-python; pip install mediapipe
Gotcha
OpenCV stores colour as BGR, not RGB
  • 5production AI apps
  • 14engineers led
  • 200+students mentored
01

Questions students ask

The OpenCV and MediaPipe questions searched most, answered from using both in shipped projects.

What is OpenCV?

OpenCV (Open Source Computer Vision Library) is a free library of several thousand functions for working with images and video: reading from files and cameras, converting colour spaces, resizing and cropping, filtering and edge detection, finding contours and shapes, geometric transforms, camera calibration, feature matching, optical flow, and a DNN module that runs neural networks from ONNX and other formats. It is written in C++ for speed with bindings for Python, Java and other languages. Almost every vision pipeline uses it somewhere, usually for the steps before and after the neural model: capture, preprocessing, drawing results.

What does OpenCV stand for?

Open Source Computer Vision. The project started at Intel in 1999 to accelerate vision research and was first released publicly in 2000; it has been maintained by a non-profit foundation and a wide community since, under a permissive licence that allows commercial use. The name reflects its purpose: a shared, open set of well-tested building blocks so that researchers and developers would not keep rewriting image processing from scratch. In Python the package is imported as cv2, a name left over from the second major API, which confuses every beginner once.

How to install OpenCV in Python

In a virtual environment, install the opencv-python package with pip; it includes the main modules and the GUI functions for showing windows. For the extra modules (such as tracking algorithms and some face tools), install opencv-contrib-python instead, never both. On servers without a display, the headless variants avoid pulling GUI dependencies. Verify by importing cv2 and printing its version. If import fails on Linux, missing system libraries for the GUI are the usual cause and the headless package fixes it. For GPU support, see the GPU answer below; the pip wheels are CPU-only.

How to use OpenCV in Python

  • Read an image with imread; it returns a NumPy array of shape height by width by channels, in BGR order.
  • Capture video with VideoCapture from a file or camera index; read frames in a loop; release at the end.
  • Convert colour with cvtColor (BGR to RGB, grayscale, HSV); resize with resize; crop by slicing the array.
  • Filter with GaussianBlur, detect edges with Canny, threshold, find contours, and draw boxes and text with rectangle and putText.
  • Run a neural network with the dnn module by loading an ONNX file, or hand frames to another library such as ONNX Runtime or MediaPipe.
  • Show results with imshow in a window, or write frames with VideoWriter; in notebooks convert to RGB and display with matplotlib.

How does OpenCV work?

Images are arrays: a grayscale image is a two-dimensional grid of intensities, a colour image a three-dimensional array with a channel per colour. OpenCV functions are optimised C++ routines that operate on those arrays, often using vector instructions and multiple cores, and in Python they operate directly on NumPy arrays without copying, so mixing OpenCV and NumPy is natural and fast. Higher-level algorithms (feature detectors, calibration, the DNN module) are built from the same primitives. Understanding that an image is just an array you can index, slice and compute on is the main conceptual step; the rest is learning which function does which transform.

Why does OpenCV use BGR?

Historical convention. When OpenCV was created, common camera drivers, Windows bitmap files and some hardware stored pixels in blue-green-red order, so the library adopted BGR as its default and never changed it, to keep compatibility with two decades of code. Nearly everything else, including matplotlib, PIL, web browsers and most neural networks, expects RGB. The practical rule: convert with cvtColor when you hand an OpenCV image to another library, and convert back before using OpenCV's drawing or writing functions. Red faces that look blue are the classic symptom of forgetting.

Can OpenCV use GPU?

Yes, in two ways, neither available in the default pip package. The CUDA modules run many functions and the DNN module on NVIDIA GPUs, but require building OpenCV from source with CUDA enabled, which takes an hour and matching driver and toolkit versions. The transparent API uses OpenCL through the UMat type to accelerate supported functions on any GPU with less setup. For neural networks specifically, it is often simpler to leave OpenCV on the CPU for capture and preprocessing and run the model in a dedicated runtime (PyTorch, ONNX Runtime with a GPU provider, or TensorRT) that handles the GPU well. Measure before building from source; many pipelines are not limited by OpenCV.

What is MediaPipe?

MediaPipe is Google's open-source framework for on-device machine learning pipelines, best known for its ready-to-use solutions: hand landmark tracking (21 points per hand), face detection and the dense face mesh, body pose landmarks, object detection, image segmentation, gesture recognition, and more, all running in real time on CPUs, phones and browsers. The current API, MediaPipe Tasks, packages each solution as a small model file and a simple class you call on an image or video frame. It is the fastest route from a webcam to tracked hands or a face mesh, and it powers many AR filters, fitness apps and sign-language projects.

How to install MediaPipe

In a virtual environment, install the mediapipe package with pip; it ships prebuilt wheels for Windows, macOS and Linux for supported Python versions, so check the version compatibility table if pip cannot find a wheel. The solutions' model files are downloaded separately from the documentation and passed to the task by path. For the browser, the Tasks Vision package is available through npm or a CDN and runs the same models with WebAssembly and WebGPU. For Android and iOS there are native libraries. Verify the install by running the hand landmark example on a webcam frame; it should draw 21 points per hand within a second of starting.

How to use MediaPipe

  • Choose a task (hand landmarker, face landmarker, pose landmarker, object detector, image segmenter) and download its model file.
  • Create the task with options: the model path, running mode (image, video or live stream), and the number of hands or faces to track.
  • Capture frames with OpenCV, convert BGR to RGB, wrap the frame as a MediaPipe image, and call detect (or detect_for_video with a timestamp).
  • Read the result: landmark coordinates normalised to the frame, plus handedness, blendshapes or segmentation masks depending on the task.
  • Draw with the provided drawing utilities or your own OpenCV calls; convert back to BGR to display.
  • Build on the landmarks: gesture rules, exercise counting, eye tracking, or features for a small classifier you train yourself.
02

First vision project this weekend

OpenCV for the frames, MediaPipe for the person.

  1. 01

    Webcam loop

    OpenCV VideoCapture, show frames, draw a timestamp; understand the array.

  2. 02

    Track a hand

    MediaPipe hand landmarker on each frame; draw the 21 points.

  3. 03

    Make it do something

    Count raised fingers, control a slider, or recognise three gestures with simple rules.

  4. 04

    Ship it

    Move the same model to the browser with the Tasks Vision package so nothing is uploaded.

03

In the room

Where these systems get explained to students.

Learning vision with a real project?

I run hands-on workshops where students go from a webcam loop to a shipped browser app in a day.