The answersDownload the PDF
Worksheet

4.4 Colour

Vision · Robot club · about 20 min

BugBotLab
NameClassDate

What this lesson is about

The blob detector: one colour at a time, area and box width as distance.

Questions 7 marks in all

  1. [1 mark]A blob is [cx, cy, area, x0, y0, x1, y1, aspect]. What is blob[2]?

    1. AThe area, in pixels
    2. BThe distance, in cm
    3. CThe left edge of its box
    4. DIts colour
  2. [1 mark]What does this program print?

    blob = [220, 110, 900, 205, 95, 235, 125, 1.0]
    width = blob[5] - blob[3]
    print(width)
    print("left" if blob[0] < 160 else "right")
  3. [1 mark]The program has read the red blobs. How does it read the blue ones?

    1. ACall set_cv("blob", "blue"), then blobs() again
    2. BCall blobs("blue")
    3. CLook further down the list from blobs()
    4. DCall set_cv("blue")
  4. [1 mark]Why is the box width a better guide to distance than the area?

    1. AArea grows with the square of the size, so it changes much faster
    2. BArea is always 0 for a ball
    3. CWidth is measured in cm
    4. DWidth does not change as the ball gets closer
  5. [1 mark]What does this program print?

    red = [100, 120, 400, 90, 110, 110, 130, 1.0]
    blue = [250, 118, 1600, 230, 98, 270, 138, 1.0]
    balls = {"red": red, "blue": blue}
    nearer = max(balls, key=lambda name: balls[name][5] - balls[name][3])
    print(nearer, "is nearer")
  6. [1 mark]A blob's box is 60 pixels wide and 20 pixels high. What is its aspect?

  7. [1 mark]Why does a blob have no distance, when a tag does?

    1. AThe detector does not know how big the red thing really is
    2. BThe camera cannot measure distance at all
    3. CColours are always far away
    4. DYou have to call distance() inside blobs()

The task: red or blue

Without driving, print left: <colour> and right: <colour> for the two balls.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# camera: look for red blobs
set_cv("blob", "red")
print(blobs())

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/4-4-colour/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print which ball is nearer, using the box width.
  2. Drive to the blue ball and stop 10 cm from it, checking with distance().
  3. Look for green and yellow too. What does blobs() return when there is nothing of that colour?