Vision · Robot club · about 20 min
The blob detector: one colour at a time, area and box width as distance.
[1 mark]A blob is [cx, cy, area, x0, y0, x1, y1, aspect]. What is blob[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")30 right
The box width is x1 - x0, 235 - 205 = 30. cx is 220, over 160, so the blob is on the right.
[1 mark]The program has read the red blobs. How does it read the blue ones?
set_cv("blob", "blue"), then blobs() againblobs("blue")blobs()set_cv("blue")set_cv, then read again.[1 mark]Why is the box width a better guide to distance than the area?
[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")blue is nearer
Red is 20 pixels wide and blue is 40. Same size ball, looks bigger, so blue is the nearer one.
[1 mark]A blob's box is 60 pixels wide and 20 pixels high. What is its aspect?
[1 mark]Why does a blob have no distance, when a tag does?
distance() inside blobs()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())The hint students can ask for: Look for each colour in turn and use cx to say which side it is on: print left: <colour> and right: <colour>. Do not drive.
from bugbot import *
connect()
set_cv('blob', 'red')
red = blobs()[0]
set_cv('blob', 'blue')
blue = blobs()[0]
if red[0] < blue[0]:
print('left: red')
print('right: blue')
else:
print('left: blue')
print('right: red')
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.