@@ -25,6 +25,7 @@ def tensor_to_image(self, tensor):
2525 img_np = np .array (tensor ).astype (np .float32 ) / 255.0
2626 return torch .from_numpy (img_np ).unsqueeze (0 )
2727
28+
2829class FisheyeNode (FisheyeBase ):
2930 @classmethod
3031 def INPUT_TYPES (cls ):
@@ -33,8 +34,8 @@ def INPUT_TYPES(cls):
3334 "image" : ("IMAGE" ,),
3435 "mapping" : (["equidistant" , "equisolid" , "orthographic" , "stereographic" ],),
3536 "format" : (["fullframe" , "circular" ],),
36- "fov" : ("FLOAT" , {"default" : 180.0 , "min" : 0.0 , "max" : 360.0 , "step" : 0.1 }),
37- "pfov" : ("FLOAT" , {"default" : 120.0 , "min" : 0.0 , "max" : 360.0 , "step" : 0.1 }),
37+ "fov" : ("FLOAT" , {"default" : 180.0 , "min" : 0.0 , "max" : 360.0 , "step" : 30.0 }),
38+ "pfov" : ("FLOAT" , {"default" : 120.0 , "min" : 0.0 , "max" : 360.0 , "step" : 30.0 }),
3839 },
3940 }
4041
@@ -47,29 +48,30 @@ def map_fisheye(self, i, j, width, height, dim, xcenter, ycenter):
4748 yd = j - ycenter
4849 rd = hypot (xd , yd )
4950
50- rn = rd / ( dim / 2 )
51+ rmax = dim / 2 if self . format == "circular" else hypot ( width / 2 , height / 2 )
5152
52- theta = rn * (self .fov * pi / 360 )
53+ phiang = arctan (rd / rmax )
54+ theta = phiang * self .pfov / (self .fov / 2 )
5355
54- # See https://en.wikipedia.org/wiki/Fisheye_lens
5556 if self .mapping == "equidistant" :
56- r = theta
57+ r = rmax * theta / ( pi / 2 )
5758 elif self .mapping == "equisolid" :
58- r = 2 * sin (theta / 2 )
59+ r = 2 * rmax * sin (theta / 2 )
5960 elif self .mapping == "orthographic" :
60- r = sin (theta )
61+ r = rmax * sin (theta )
6162 elif self .mapping == "stereographic" :
62- r = 2 * tan (theta / 2 )
63-
64- r = r * (dim / 2 )
63+ r = 2 * rmax * tan (theta / 2 )
6564
6665 rdmask = rd != 0
67-
6866 xs = xd .astype (np .float32 ).copy ()
6967 ys = yd .astype (np .float32 ).copy ()
7068
71- xs [rdmask ] = (r [rdmask ] / rd [rdmask ]) * xd [rdmask ] + xcenter
72- ys [rdmask ] = (r [rdmask ] / rd [rdmask ]) * yd [rdmask ] + ycenter
69+ scale = 1.0
70+ if self .mapping == "equidistant" :
71+ scale = 1.5
72+
73+ xs [rdmask ] = scale * (rd [rdmask ] / r [rdmask ]) * xd [rdmask ] + xcenter
74+ ys [rdmask ] = scale * (rd [rdmask ] / r [rdmask ]) * yd [rdmask ] + ycenter
7375
7476 xs [~ rdmask ] = xcenter
7577 ys [~ rdmask ] = ycenter
@@ -108,8 +110,8 @@ def INPUT_TYPES(cls):
108110 "image" : ("IMAGE" ,),
109111 "mapping" : (["equidistant" , "equisolid" , "orthographic" , "stereographic" ],),
110112 "format" : (["fullframe" , "circular" ],),
111- "fov" : ("FLOAT" , {"default" : 180.0 , "min" : 0.0 , "max" : 360.0 , "step" : 5 .0 }),
112- "pfov" : ("FLOAT" , {"default" : 120.0 , "min" : 0.0 , "max" : 360.0 , "step" : 5 .0 }),
113+ "fov" : ("FLOAT" , {"default" : 180.0 , "min" : 0.0 , "max" : 360.0 , "step" : 30 .0 }),
114+ "pfov" : ("FLOAT" , {"default" : 120.0 , "min" : 0.0 , "max" : 360.0 , "step" : 30 .0 }),
113115 },
114116 }
115117
0 commit comments