1

I'm trying to get a robot to identify a line on the ground and follow it.
I've searched the internet and found many examples of line following robots, but all of them are using specialized sensors to detect the line.
I'd like to use the camera on the robot for that purpose.

I'm new to the field of computer vision, so I'd like some advice on how to approach the problem. Specifically, how can I detect the line and its angle/direction in relation to the robot? How can I detect turns?

Update following nikies comment:
How the line looks is up to me, i was thinking to put some bright colored tape on the ground, but i can use whatever is easiest...
The camera can take both color and b&w image.
Lighting and location may vary but i'll worry about it later, i just want to know what to look for to get started. Is there a "common" way to do it ?

yurib
  • 8,043
  • 3
  • 30
  • 55
  • 3
    This depends on many things: What does the line look like, what does the background look like? How can you tell the line apart from other edges in the image? What kind of camera do you want to use (color or greyscale, resolution)? What kind of lighting do you have? If you want practical advice, it would be best to post a few images taken with the right camera with the right kind of lighting, from the point of view of the robot. – Niki Dec 13 '11 at 20:15
  • i updated the post to answer your questions – yurib Dec 13 '11 at 22:21

4 Answers4

6

Here's one approach, suitable for refinement.

Through a combination of zooming, a pixellation filter, and thresholding, reduce the camera input to a 3 by 3 grid of white or black squares. With suitable adjustment, the reduction should be able to blow up the line such that it takes up exactly three of the reduced pixels. The robot's logic then consists of moving in one of eight directions to keep the center pixel black.

The image after reduction:

☐ ■ ☐
☐ ■ ☐ ↑ move forward one unit
☐ ■ ☐

What a left turn looks like:

☐ ☐ ☐
■ ■ ☐ ← turn 90 degrees left
☐ ■ ☐

This is a very simple scheme, and converting the video input to a clean 3 by 3 grid isn't a trivial task, but it should be enough to get you moving in the right direction.

unkulunkulu
  • 11,576
  • 2
  • 31
  • 49
blahdiblah
  • 33,069
  • 21
  • 98
  • 152
1

One option is to use OpenCV or a similar image processing / vision library together with camera looking forward and downward to do the following:

  1. Place a tape of a known, unusual, and bright color such as yellow or orange. If you're willing to mount a light source on your robot, you might even use retroreflective tape.
  2. Use OpenCV to break the color video image into three HSV planes - hue (color), saturation, and value (intensity).
  3. Use a Stroke Width Transform to identify the line. The following StackOverflow post has a link to a video about the SWT: Stroke Width Transform (SWT) implementation (Java, C#...)
  4. Apply a thinning algorithm (Stentiford or Zhang-Suen) to reduce the segmented tape line to a single pixel width.
  5. Treat the single pixels as input points for a curve fit. Or, more simply, calculate the angle from end point to end point for every group of N successive points in your line.
  6. Apply a little 3D geometry as well as information about your robot's current direction and speed to calculate the time at which it must turn, and how sharply, in order to follow the line.

If your robot moves slowly, then a camera looking downward might be more suitable. The calculations are easier, but the robot wouldn't be able to look ahead as far.

Community
  • 1
  • 1
Rethunk
  • 3,976
  • 18
  • 32
0

How fast does your robot need to move? There are AI (Artificial Inteligence) options (which will be slower than making easy decisions as described in the other answer.

In the AI field, you could investigate:

Self organising maps (SOM) to try and do reasoning on the black line. You can teach it to identify shapes (I have used it to identify letters before). I think this can be calculated fairly quickly on a modern computer but depends on your robots hardware (can't entirely remember).

AI techniques take quite a while to train, and for you to learn. The other answer is also a good option if you wanted a fixed code way of doing it.

Dessus
  • 2,147
  • 1
  • 14
  • 24
0

Well, there are a number of things you can do. I would start by reading about union-find algorithms, if you don't know them. Depending on your environment, you might be able to get away with 1) contrast-normalizing or performing histogram equalization on the image, then 2) adding all pixels roughly meeting your line color to a union find data structure. For robustness (if you have a color camera), I would pick something that shows up really strongly, like bright orange, instead of black, which contains no hue information and will be detected everywhere.

From there, you need some way to make decisions based on the processed data. You can imagine writing a simple (though surely imperfect) algorithm to guess which of the image segments is the line, calculate its orientation, and compute a turning direction for your controller. Perhaps you scan a few horizontal lines in the image and fit a line to the maximal responses from your filter. This might get you most of what you want. Maybe you can come up with something more clever based on your hardware, or, for example, enforce that the line always runs from the bottom of the image to some height.

If you're really ambitious and skilled with math, you should read up on (camera) lens calibration. Essentially, by fitting a mathematical model to your camera lens and assuming everything in the image is on the ground beneath the robot, you could actually figure out where the line runs in 3D with respect to your robot. This last step, though, will require a significant amount of knowledge, though, so don't expect it to be easy!

chardson
  • 143
  • 2
  • 7