Generate a rect camera path that looks at x_center, y_center Args: num_poses: number of camera poses sampled on the rect d_to_origin: distance to the origin x_length: length of x side y_length: length of y side
(
num_poses: int,
d_to_origin: float,
x_length: float,
y_length: float,
center_angles: T.Union[torch.Tensor, np.ndarray, T.List[float]],
x_center: float = 0,
y_center: float = 0,
invert_yz: bool = True,
alt_yaxis: bool = False,
)
| 2137 | |
| 2138 | |
| 2139 | def generate_camera_rect_path( |
| 2140 | num_poses: int, |
| 2141 | d_to_origin: float, |
| 2142 | x_length: float, |
| 2143 | y_length: float, |
| 2144 | center_angles: T.Union[torch.Tensor, np.ndarray, T.List[float]], |
| 2145 | x_center: float = 0, |
| 2146 | y_center: float = 0, |
| 2147 | invert_yz: bool = True, |
| 2148 | alt_yaxis: bool = False, |
| 2149 | ) -> T.Union[torch.Tensor, np.ndarray]: |
| 2150 | """ |
| 2151 | Generate a rect camera path that looks at x_center, y_center |
| 2152 | Args: |
| 2153 | num_poses: |
| 2154 | number of camera poses sampled on the rect |
| 2155 | d_to_origin: |
| 2156 | distance to the origin |
| 2157 | x_length: |
| 2158 | length of x side |
| 2159 | y_length: |
| 2160 | length of y side |
| 2161 | x_center: |
| 2162 | center of x side |
| 2163 | y_center: |
| 2164 | center of y side |
| 2165 | center_direction: |
| 2166 | (2,) theta (angle between x-axis), phi (angle between xy plane), |
| 2167 | the viewing direction of the center of the circle. All in degree. |
| 2168 | The angles are given in the final coordinate (after yz is inverted) |
| 2169 | invert_yz: |
| 2170 | whether to invert the direction of y axis and z axis (since images y coord is flipped) |
| 2171 | This is to account for the difference in the image coordinate (x to right, y to down, z to far) |
| 2172 | and the world/opengl coordinate (x to right, y to up, z to us) |
| 2173 | alt_yaxis: |
| 2174 | an option to use an alternative definition of yaxis and makes a more stable circular path |
| 2175 | Returns: |
| 2176 | (num_poses, 4, 4) camera poses (that converts camera coord to world coords) |
| 2177 | """ |
| 2178 | |
| 2179 | if isinstance(center_angles, np.ndarray): |
| 2180 | center_angles = torch.from_numpy(center_angles).float() |
| 2181 | elif isinstance(center_angles, (list, tuple)): |
| 2182 | center_angles = torch.tensor(center_angles).float() |
| 2183 | |
| 2184 | center_angles = center_angles.float() |
| 2185 | |
| 2186 | if invert_yz: |
| 2187 | # the coordinate is currently pre-yz-inverted |
| 2188 | # but center_angles are given after yz-inverted |
| 2189 | center_angles = -1 * center_angles |
| 2190 | |
| 2191 | # generate a circle on the xy plane (i.e., on the plane z = d_to_origin) |
| 2192 | thetas = torch.linspace(0, torch.pi * 2, num_poses) + torch.pi # (n,) |
| 2193 | |
| 2194 | step_size = 2 * (x_length + y_length) / num_poses |
| 2195 | |
| 2196 | # intitial poses: start from (0, y_length/2), keep increasing |