Код: Выделить всё
def uv_pano_to_uv_cubes(u_pano, v_pano, cubemap_shape, panorama_shape):
# Calculate the spherical coordinates from 2D image coordinates
phi = (u_pano / panorama_shape[0] - 0.5) * np.pi
theta = (v_pano / panorama_shape[1] + 0.25) * 2 * np.pi
# Calculate the cartesian coordinates from the spherical coordinates
x = np.cos(phi) * np.cos(theta)
y = np.sin(phi)
z = np.cos(phi) * np.sin(theta)
# Estimate on which cubemap the pixel is located
if abs(x) >= abs(y) and abs(x) >= abs(z):
face = 'E' if x > 0 else 'W'
a = z if x > 0 else -z
b = y
ma = abs(x)
elif abs(y) >= abs(x) and abs(y) >= abs(z):
face = 'D' if y > 0 else 'U'
a = x
b = z if y > 0 else -z
ma = abs(y)
else:
face = 'S' if z > 0 else 'N'
a = -x if z > 0 else x
b = y
ma = abs(z)
# Estimate the corresponding pixel on the cube
u_cube = int(((a / ma) + 1.0) * 0.5 * (cubemap_shape[0] - 1))
v_cube = int(((b / ma) + 1.0) * 0.5 * (cubemap_shape[1] - 1))
return face, u_cube, v_cube
Я пытался повысить производительность с помощью многопоточности процессора, но это не сильно помогло. Я также пытался написать шейдер OpenGL, но безуспешно.
Подробнее здесь: https://stackoverflow.com/questions/791 ... ng-the-gpu