Contour Tracing Algorithm using C Image Processing

During RoboCup Rescue Line and Maze, our team had done Computer Vision contour tracing using OpenCV’s findContours function. In the past month, Victor has focused on writing image processing code in C to make contour tracing algorithm capable of being used on embedded systems. By doing this, our team can use a vision system without a Raspberry Pi, nor the OpenCV library.

To begin, Victor used basic BMP image processing ideas to read the image in BMP format, convert it to a grayscale image, and convert it into a binary image. This resulted in an image with only two values, black and white.

Victor researched different contour tracing algorithms. The most basic algorithm was the Square Tracing Algorithm, which involves finding a 4-pixel community around the origin pixel.  Starting from the top left, and working left and down, he looked at each pixel to determine it’s value. If the value was black, then he would label this pixel as his “start pixel”, and begin the algorithm. He would check the pixel to the left of the start pixel, and if it was black, then he would label this as the “current pixel”. If the pixel was white, then he would go to the next pixel on the right. This algorithm would continue until he reached the “start pixel”. At the start pixel, this loop ended, and we had essentially found the edge of an the pixel.

However, another challenge was presented through holes. Holes are the pixels inside of the object that we have already found contours in. This problem was solved through using a hole-finding algorithm that checked for the min and max of each pixel, and shaded it out to white. The result was only contours that he wanted to see.  

This process is seen on the pictures on the right.

Original 

Gray

Binary

Contour