Skip to content
RoboLearn
Not completed

Computer vision basics

AdvancedAdvanced45 minBefore this: Cameras as sensors, MicroPython basics

What you’ll learn

  • How a computer stores an image
  • Finding a coloured object with thresholding in HSV
  • Contours, and the step up to AI object detection

Images are grids of numbers

A colour image is a grid of pixels, and each pixel has three numbers (blue, green and red in OpenCV’s order), each 0–255. A 640 × 480 image is 307,200 pixels.

HSV is better for colour

Lighting changes RGB values a lot. HSV separates Hue (the colour itself), Saturation (how strong) and Value (how bright), so “red-ish” stays in a narrow hue range even as light changes.

Finding a coloured object

  1. Convert the image to HSV.
  2. Threshold: keep only pixels within a hue/saturation/value range → a black-and-white mask.
  3. Clean the mask (erode/dilate to remove speckles).
  4. Find contours (outlines of white areas) and take the biggest.
  5. Its centre gives the object’s position; its area hints at distance.

Beyond colour

To recognise things (people, cups, signs) robots use trained neural networks (for example YOLO-family detectors) that output boxes and labels. These need more computing power: a Raspberry Pi 5 can run small models, and AI accelerators make it faster (see AI on small boards).

Finished this lesson?