how to find distance using two color servo camera?

i am having trouble calculating distance using two color servo camera example, i can do it just fine with one color but not with two. i am using labview. any help at all would be great!

Team 330’s BETA code calculates distance between the camera and the gimbal using PIDs. Perhaps you can modify it to your needs.

http://forums.usfirst.org/showthread.php?t=11298&page=2

Are you referring to calculating distance using a method similar to the one described here (by Kevin Watson)? It seems like it should be fairly easy to use the same tracking algorithm as you did for one color, but just find an average of the green and pink positions to find the center of the target, and then run your tracking algorithms off of that. You say you can do it with one color, so I won’t bother going into the details of the visual servoing or distance calculation tasks.

However, this seems trivial enough that I’m wondering if you are referring to something else. Can you provide more detail?

–Ryan

There are a couple of ways to calculate distance with a camera. The ones I can think of off the top of my head are:

  1. Figure out what part of the visual field the object occupies, and assume that higher=farther
  2. Use relative size–based on the law of perspective, the farther an object is, the fewer pixels it will occupy
  3. If the object isn’t moving, you can use the laws of parallax to calculate the distance based on apparent movement at a given robot speed.

Here’s what Team 533 did to get distance from the camera:

We started with the 2 color tracker sample project supplied by FIRST.

Once we got the tracker working, the top level VI for the 2-color camera code displayed some calculated parameters including “percentage of area”.

This number is the ratio of the size of the target as seen by the camera divided by the area of the camera’s entire field of view. The farther away the target, the smaller this ratio is. The percentage of area ratio is approximately proportional to the reciprocal of the square of the distance. So distance is approximately proportional to the reciprocal of the square root of the “percentage of area” value:

DISTANCE = K / SQRT(% OF AREA)

(there is a more exact relationship that involves trigonometric functions but the above simple approximation is good enough to judge distances to within a few inches)

We placed the target exactly 4 feet away from the camera and measured the % of area value, then solved for K:

K = (4 feet) * SQRT(Measured % of area when target is at 4 feet).

Next we programmed the formula DISTANCE = K / SQRT(% OF AREA) with the
K value we measured and added an indicator to the fromt panel.

Finally, we tested the revised code at various distances. Since the equation is only an approximation, there is some error but we were able to obtain distance measurements within a few inches using this method.

Neil
Advisor, Team 533