3

After extensive search, I have not been able to find a decently explained formula for WebGL fisheye image correction. A Shadertoy at fisheye/antifisheye shows a formula

uv = m + normalize(d) * atan(r * -power * 10.0) * bind / atan(-power * bind * 10.0);

which is literally described as "weird formula". It somehow follows Paul Burke's work on lens distortion correction here, but I do not see the connection. In my application, the formula boils down to (values are hand-tuned to my lens and webcam):

uv = centerPoint + normalize(d) * atan(r * pi) * 1/3 / atan(pi/3)

Where r is the distance of a pixel from center of the image, d is the unit vector in that direction and centerPoint is, well, the center of the image. I don't understand how can the arctangent be tied directly to the coordinates, can anyone help me get it? I do get that the part of the formula with arc tangents is calculation of pixel distance from the image center, what I do not understand is how is that computed.

Thanks!

Michael
  • 173
  • 1
  • 11
  • add image of your visualization setup ... fisheye corrections usually transform fragmets/geometry so perpendicular distance from camera match the depth coordinate. In some cases it is by multipliyng by `cos` in others it is `tan` or other formulas all depends on what and how are you viewing (kind of projection and viewed geometry and also distance from camera) ... – Spektre Sep 28 '15 at 06:22

1 Answers1

1

Ok, so after some searching and asking around, I understood what happens in the formula. A diagram and basic formulas are on the image below: on this image]1. Since the xy' position is known - it's the target position on the texture, we calculate xy - source pixel on the fisheye image. R is the fisheye image radius. We can substitute a desired value of d depending on maximum view angle we want to achieve (since tangent function goes to infinity at 90 deg and tan(B) = 1/d, it's nice to take a reasonable value). After transformations, we get to:

xy= atan(xy'/d)* 2R/pi

which is the theoretically correct formula for equidistant projection, which we assume is performed in the lens. The formula I referenced in the original post had something else instead of 2R/pi and it still worked because of imperfections in the lens - it most probably has some strange function we'll never know and it worked as an approximation.

There, I hope it was understandable, in case of any questions, I'll be happy to answer them :)

Michael
  • 173
  • 1
  • 11