Context:

SCSE CC is a competition that invites teams of students to work on a computing project. For 2022, we were tasked to program a robot car to travel along a path based on shape instructions that it sees with a camera. I was assigned the role of writing the algorithm for detecting shapes.


The whole process took me about a month or two to complete, and I tried to take photos in random conditions to help improve the algorithm. Testing was done on a Raspberry Pi as that was the platform used by the robot car.

The algorithm was written in Python.

Libraries used:

  • scipy.spatial.dist was used to calculate the distance between 2 colour points.
  • numpy was used to speed up calculations on matrices (since images are like 2D matrices).
  • cv2 and imutils was used to conduct image processing.

Rough Description of Algorithm: Step 0

  1. Image is blurred to remove noise. Step 1
  2. All regions outside of white regions (paper) are removed. Step 2
  3. White regions are removed to isolate shapes. Step 3
  4. Pure red, green and blue (all possible colours for shapes) are exaggerated to further isolate shapes. Step 4
  5. Otsu’s method is used to ensure there are only non-shape pixels and shape pixels. Step 5
  6. Gradient around the edges of shape are calculated to determine how many points they have. (This part was largely taken from the internet) Step 6
  7. Shape and colour of shape is determined.
    • Triangles have 3 points, squares have 4 points, and anything with more points is considered a circle.
    • Red, green or blue colour is determined by the shape’s colour’s euclidean distance from each other. Euclidean distance in colour space