Thursday, July 10, 2008

Vision Software

In order to guide the robot I need to process video data from a camera. Initially, the goal is to get the robot to travel down a course defined by two rows of orange cones. This is the basis of the Waterloo Robot Racing competition. A simple algorithm to guide the robot tries to detect two rows of cones as lines forming two sides of a triangle. By heading towards the center of the triangle we will (roughly) head down the course. Obviously, we'll have to handle cases where the robot can't see two distinct lines. This can happen when the robot isn't pointing down the course, or when the rows of cones don't resolve themselves into easily distinguished rows.

For now, I'm using OpenCV to capture frames from a camera. This is surprisingly easy to do with many USB or firewire cameras when you have drivers. OpenCV also provides the functions for the colour space conversion to HSV and the Hough transform line detection. The algorithm looks like this:

  1. Capture a frame from the camera
  2. Convert the image to the HSV (hue, saturation, value) colour space. The hue channel tells us the colour of the pixel as an angle in a colour wheel. The saturation channel tells us how strong the colour is.
  3. Create a binary image where a pixel is zero unless the corresponding image pixel has a hue angle near to orange and a high saturation.
  4. Use a Hough Transform to detect lines in the binary image. The Hough Transform works by comparing many candidate lines to the image, and letting pixels "vote" for any line they lie upon. It returns the lines that have large numbers of votes.
  5. Group the lines into those with positive vs. negative slope. Compute an average for each group of lines.
  6. The triangle is formed by these two average lines. The bottom of the image provides the third line. Compare the center of the triangle to the vertical centerline of the image to get a value for the robot's steering.

No comments: