Skip to content

Commit

Permalink
fix invalid py3.9 type hint. Fix perspective h/w
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Jan 4, 2025
1 parent ef4ac14 commit b6e59bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
15 changes: 13 additions & 2 deletions py360convert/e2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def e2p(
e_img: NDArray[DType],
fov_deg: Union[float, int, tuple[float | int, float | int]],
fov_deg: Union[float, int, tuple[Union[float, int], Union[float, int]]],
u_deg: float,
v_deg: float,
out_hw: tuple[int, int],
Expand Down Expand Up @@ -65,7 +65,18 @@ def e2p(
u = -float(np.deg2rad(u_deg))
v = float(np.deg2rad(v_deg))
in_rot = float(np.deg2rad(in_rot_deg))
sampler = EquirecSampler.from_perspective(h_fov, v_fov, u, v, in_rot, h, w, order)
sampler = EquirecSampler.from_perspective(
h_fov,
v_fov,
u,
v,
in_rot,
h,
w,
out_hw[0],
out_hw[0],
order,
)
pers_img = np.stack([sampler(e_img[..., i]) for i in range(e_img.shape[2])], axis=-1)

return pers_img[..., 0] if squeeze else pers_img
16 changes: 11 additions & 5 deletions py360convert/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ def from_cubemap(cls, face_w: int, h: int, w: int, order: int):

@classmethod
@lru_cache(_CACHE_SIZE)
def from_perspective(cls, h_fov: float, v_fov: float, u, v, in_rot: float, h: int, w: int, order: int):
def from_perspective(
cls, h_fov: float, v_fov: float, u, v, in_rot: float, in_h: int, in_w: int, out_h, out_w, order: int
):
"""Construct a EquirecSampler from perspective specs.
Parameters
Expand All @@ -446,16 +448,20 @@ def from_perspective(cls, h_fov: float, v_fov: float, u, v, in_rot: float, h: in
Vertical viewing angle in radians
in_rot: float
Inplane rotation in radians.
h: int
in_h: int
Height of input equirec image.
w: int
in_w: int
Width of input equirec image.
out_h: int
Height of output perspective image.
out_w: int
Width of output perspective image.
order: int
The order of the spline interpolation. See ``scipy.ndimage.map_coordinates``.
"""
xyz = xyzpers(h_fov, v_fov, u, v, (h, w), in_rot)
xyz = xyzpers(h_fov, v_fov, u, v, (out_h, out_w), in_rot)
u, v = xyz2uv(xyz)
coor_x, coor_y = uv2coor(u, v, h, w)
coor_x, coor_y = uv2coor(u, v, in_h, in_w)
return cls(coor_x, coor_y, order=order)


Expand Down

0 comments on commit b6e59bc

Please sign in to comment.