Lab 4

Lab 4: Ball detection

In this lab you will write an algorithm to detect a black ball in images captured by Cozmo.

1. As a first step get the latest labs repository from GitHub to obtain the starter code for Labs 4 and 5. For Lab 4 you are provided the following directory of files:

    • find_ball.py – this is the main file where you will enter your solution. Complete the function find_ball() to return the location and radius of the ball in the image (if any). You may edit any part of this file and add helper functions as needed, but make sure your code is self-contained because this is the only file you will be submitting.
    • autograder.py – this autograder is provided to help you verify your solution. We will use the same autograder with a new set of images to verify your code.
    • imgs/ - directory containing images and a text file listing the true location of the ball in each image

The code converts images into OpenCV format to allow for easy manipulation and editing. Verify that when you run autograder.py the output for all images is None, with the final line reading: score = 10.

2. Complete the code to detect the ball location. Your function should return [x, y, r] where x and y are the coordinates of the center of the ball, and r is the radius of the ball (all measured in pixels). If no ball is found, return [0,0,0] or None.

We will evaluate the performance of your algorithm on 100 images using the auto grader. 50 of these images will be the same as the ones that you are provided with the assignment, and 50 will be new images taken under the same conditions. Your grade will be determined as the percentage of the images in which the location of the ball is correctly reported.