# Distance to April Tag

Generally cameras can estimate distance based on the size of an object or the angle to the item, an April Tag for example. Neither of these are terribly accurate.

It seems that if the camera can view two April tags in one field of view then your accuracy could dramatically improve. Then you get the additional information of the angle between the April tags and mix this with the known position of the April tags would provide a lot more accuracy to locate the bot. For example looking at the grid and viewing two or even three April tags.

Does the Limelight do this with its Mega tags that orients to the field layout? The documentation is not at all clear.

I don’t know how limelight does it, but photonvision’s multi-tag estimation strategy (the one you can use when multiple apriltags are in view) utilizes the solvepnp algorithm (programmatically just a call to opencv’s `solvepnpgeneric` method). This function takes in the pixel position of the corners of the apriltags in the captured frame as well as their 3d position on the field and spits out the 3d position of the camera. Don’t know if limelight does something similar .

The core of the technical problem boils down to two steps:

1. in a 2d image, Identify interesting features on objects for which you have some knowledge of their location.
2. project the 2d coordinates back to 3 dimensions

A key step involves making sure data for #1 is good to start, as this will fundamentally limit any strategy for #2.

Considering all tag corners together helps reduce ambiguity issues. However, I’m not certain whether it mathematically guarantees better accuracy than individually considering each tag.

Yes, it does. MegaTag is just a fancy name for using multiple tags for a single estimation.

Great. It is locating multiple known April Tag objects in its field of view and estimating the robot position from them. There are multiple inputs that are combined together to give a single output. Each input has noise, uncertainty, etc and combining them together lowers that uncertainty. To do this the system is making some sort of best fit to the data. The computer will always return an answer. But sometimes the inputs are garbage (poor lighting, obscuration, blur, etc.) and then the output is garbage. Whenever I have a computer do that it helps to get an error estimate so you can decide how well to believe the value. Does the limelight megatag give any type of error, goodness of fit, chi-squared?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.