Last active
September 2, 2022 07:36
-
-
Save ThomasParistech/2c88b8a10c280e78bf000fdd085f333b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List | |
| import numpy as np | |
| import cv2 | |
| def cubemap_to_equirec(cubefaces: List[np.ndarray]) -> np.ndarray: | |
| """Convert a list of cubefaces (FRBLUD) into an equirectangular image""" | |
| # Stack cubefaces horizontally | |
| cubemap = np.hstack(cubefaces) | |
| # Set the width of the output image to a multiple of 8 | |
| face_size = cubemap.shape[0] | |
| out_height = (int(face_size * np.pi) // 8) * 4 | |
| out_width = out_height * 2 | |
| # XY maps | |
| frbl_x, frbl_y = get_frbl_maps(out_width, out_height, face_size) | |
| ud_x, ud_y = get_ud_maps(out_width, out_height, face_size) | |
| # Combine | |
| ceiling = get_up_mask(out_height, out_width).astype(np.float32) | |
| ceiling += np.flipud(ceiling) | |
| map_x = ceiling*ud_x + (1-ceiling)*frbl_x | |
| map_y = ceiling*ud_y + (1-ceiling)*frbl_y | |
| # Opencv shift | |
| map_x -= 0.5 | |
| map_y -= 0.5 | |
| return cv2.remap(cubemap, map_x, map_y, cv2.INTER_CUBIC, | |
| borderMode=cv2.BORDER_REPLICATE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment