Get intrinsic and extrinsic of a camera. Args: k_dim (int, optional): Dimension of the returned mat K. Defaults to 3. Raises: ValueError: k_dim is neither 3 nor 4. Returns: List[np.ndarray]:
(self, k_dim=3)
| 157 | self.set_value('translation', T_vec.tolist()) |
| 158 | |
| 159 | def get_KRT(self, k_dim=3) -> List[np.ndarray]: |
| 160 | """Get intrinsic and extrinsic of a camera. |
| 161 | |
| 162 | Args: |
| 163 | k_dim (int, optional): |
| 164 | Dimension of the returned mat K. |
| 165 | Defaults to 3. |
| 166 | |
| 167 | Raises: |
| 168 | ValueError: k_dim is neither 3 nor 4. |
| 169 | |
| 170 | Returns: |
| 171 | List[np.ndarray]: |
| 172 | K_mat (np.ndarray): |
| 173 | In shape [3, 3]. |
| 174 | R_mat (np.ndarray): |
| 175 | Rotation from world to view in default. |
| 176 | In shape [3, 3]. |
| 177 | T_vec (np.ndarray): |
| 178 | Translation from world to view in default. |
| 179 | In shape [3,]. |
| 180 | """ |
| 181 | K_3x3 = self.get_mat_np('in_mat') |
| 182 | R_mat = self.get_mat_np('rotation_mat') |
| 183 | T_vec = np.asarray(self.get_value('translation')) |
| 184 | if k_dim == 3: |
| 185 | return [K_3x3, R_mat, T_vec] |
| 186 | elif k_dim == 4: |
| 187 | K_3x3 = np.expand_dims(K_3x3, 0) # shape (1, 3, 3) |
| 188 | K_4x4 = convert_K_3x3_to_4x4( |
| 189 | K=K_3x3, is_perspective=True) # shape (1, 4, 4) |
| 190 | K_4x4 = K_4x4[0, :, :] |
| 191 | return [K_4x4, R_mat, T_vec] |
| 192 | else: |
| 193 | raise ValueError(f'K mat cannot be converted to {k_dim}x{k_dim}') |
| 194 | |
| 195 | def set_mat_np(self, mat_key: str, mat_numpy: np.ndarray) -> None: |
| 196 | """Set a matrix-type parameter to mat_numpy. |
no test coverage detected