Skip to content

Commit 3546210

Browse files
committed
Simplify fisheye effect and fix issue with distortion
1 parent 7da0eb6 commit 3546210

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

nodes.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,29 @@ def map_fisheye(self, i, j, width, height, dim, xcenter, ycenter):
4747
yd = j - ycenter
4848
rd = hypot(xd, yd)
4949

50+
rn = rd / (dim / 2)
51+
52+
theta = rn * (self.fov * pi / 360)
53+
5054
# See https://en.wikipedia.org/wiki/Fisheye_lens
5155
if self.mapping == "equidistant":
52-
ifoc = dim * pi / (self.fov * 180)
53-
rr = rd * ifoc
54-
56+
r = theta
5557
elif self.mapping == "equisolid":
56-
ifoc = 2.0 * sin(self.fov * pi / 720)
57-
rr = 2 * arctan(rd * ifoc / dim)
58-
58+
r = 2 * sin(theta / 2)
5959
elif self.mapping == "orthographic":
60-
ifoc = 2.0 * sin(self.fov * pi / 360)
61-
rr = arctan(rd * ifoc / dim)
62-
60+
r = sin(theta)
6361
elif self.mapping == "stereographic":
64-
ifoc = 2.0 * tan(self.fov * pi / 720)
65-
rr = 2 * arctan(rd * ifoc / (2 * dim))
62+
r = 2 * tan(theta / 2)
63+
64+
r = r * (dim / 2)
6665

6766
rdmask = rd != 0
67+
6868
xs = xd.astype(np.float32).copy()
6969
ys = yd.astype(np.float32).copy()
7070

71-
ofoc = dim / (2 * tan(self.pfov * pi / 360))
72-
factor = ofoc * tan(rr)
73-
74-
xs[rdmask] = (factor[rdmask] / rd[rdmask]) * xd[rdmask] + xcenter
75-
ys[rdmask] = (factor[rdmask] / rd[rdmask]) * yd[rdmask] + ycenter
71+
xs[rdmask] = (r[rdmask] / rd[rdmask]) * xd[rdmask] + xcenter
72+
ys[rdmask] = (r[rdmask] / rd[rdmask]) * yd[rdmask] + ycenter
7673

7774
xs[~rdmask] = xcenter
7875
ys[~rdmask] = ycenter

0 commit comments

Comments
 (0)