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 enum import IntEnum | |
| from typing import Dict | |
| class CubeFace(IntEnum): | |
| FRONT = 0 | |
| RIGHT = 1 | |
| BACK = 2 | |
| LEFT = 3 | |
| UP = 4 |
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 Tuple | |
| def split_axes_convention(convention: str) -> Tuple[CubeFace, CubeFace, CubeFace]: | |
| """Parse the three axes contained in the convention string, e.g. LEFT_UP_FRONT""" | |
| splits = convention.upper().split("_") | |
| assert len(splits) == 3 | |
| return CubeFace[splits[0]], CubeFace[splits[1]], CubeFace[splits[2]] |
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 Dict, Final, Tuple | |
| def get_reference_axes(ref_convention: str) -> Dict[CubeFace, | |
| Tuple[float, float, float]]: | |
| """Get the reference coordinates of the cube directions""" | |
| x, y, z = split_axes_convention(ref_convention) | |
| return { | |
| x: (1., 0., 0.), | |
| y: (0., 1., 0.), |
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
| import numpy as np | |
| def get_transform_to_ref(convention: str) -> np.ndarray: | |
| """Get the 3x3 matrix mapping from the input convention to the reference one""" | |
| x, y, z = split_axes_convention(convention) | |
| return np.column_stack((REF_AXES[x], REF_AXES[y], REF_AXES[z])) |
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 enum import IntEnum | |
| from typing import Dict, Final | |
| import numpy as np | |
| class CoordinateSystem(IntEnum): | |
| REFERENCE = 0 | |
| PYTORCH_3D = 1 | |
| OPENCV = 2 |
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 Tuple | |
| import numpy as np | |
| def convert_vertices(verts_in: np.ndarray, | |
| system_in: CoordinateSystem, | |
| system_out: CoordinateSystem) -> np.ndarray: | |
| """Transform vertices of shape (N,3) between different coordinate systems.""" | |
| T_ref_win = WORLD_TO_REF.get(system_in, CAMERA_TO_REF[system_in]) | |
| T_ref_wout = WORLD_TO_REF.get(system_out, CAMERA_TO_REF[system_out]) |
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
| import numpy as np | |
| def sample_pixels(begin: float, end: float, n: int) -> np.ndarray: | |
| """ | |
| Sample pixel values of an affine function, which is equal | |
| to "begin" on the far left and "end" on the far right. | |
| """ | |
| x_coords = 0.5 + np.arange(n, dtype=np.float32) | |
| return begin + (end-begin) * x_coords / n # ]begin, end[ |
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 Tuple, Union | |
| import cv2 | |
| import numpy as np | |
| def solve(penalty_map: np.ndarray, | |
| mask: Union[Tuple[int, int], np.ndarray], | |
| target_x: float, | |
| target_y: float, | |
| dist_weight: float) -> Tuple[int, int]: |
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
| import fire | |
| from typing import List | |
| import pandas as pd | |
| from players_info import PlayerInfo, ListOfPlayerInfo | |
| def parse_form(form_csv: str) -> List[List[PlayerInfo]]: | |
| df = pd.read_csv(form_csv, delimiter=",") | |
| df = df.drop(["Timestamp"], axis=1) |
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
| import numpy as np | |
| from typing import Tuple | |
| def cartesian_to_spherical(xyz: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: | |
| """Convert (x,y,z) to (phi, theta, r) coordinates""" | |
| list_r = np.linalg.norm(xyz, axis=1) | |
| list_phi = np.arcsin(xyz[:, 1]/list_r) | |
| list_theta = np.arctan2(xyz[:, 0], xyz[:, 2]) | |
| return list_phi, list_theta, list_r |