FixTheRobot Explore Robotics / Perception / P2 / P2-L1

This lab works on phones, but writing code is much easier on a laptop.

Perception · Image Processing for Robotics · P2-L1 · Beginner

Detect Colored Objects in an Image

A sorting robot has to find the red blocks on a table. Its camera image is full of numbers, and the red blocks are not the brightest or the darkest thing in it.

You will pick the right colour description, write the mask, and turn the mask into a list of objects with centres.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math (and slamkit for small matrix helpers: matmul, transpose, solve, inverse, identity). Images, point clouds and detections arrive as lists inside the dictionary D; an image is a list of rows, each row a list of pixels. There is no NumPy or OpenCV: you write the algorithm yourself, which is the point of the lab. Print with print().

    Hints

    What this lab teaches

    Stage 1 explores hue, saturation and value by hand on bright and dim images. Stage 2 asks you to write the mask, including the wrap-around of red. Stage 3 groups the mask into objects, separates blocks of the same colour and rejects isolated noise. Your code is graded on hidden images; the simulator keeps the true block positions private.

    Theory for this lab

    Image Processing for Robotics labs

    1. P2-L1: Detect Colored Objects in an Image: this lab.
    2. P2-L2: Tune Thresholds Under Changing Lighting
    3. P2-L3: Diagnose a Failing Image-Processing Pipeline

    Educational simplification: simulated 40 by 28 pixel images with flat-coloured rectangular blocks, a grey floor, Gaussian pixel noise and brightness scaled by a light level. Real images have shadows, highlights, textures and camera white balance. All images in this lab are simulated.

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.