retrieval_context ¶
Functions:¶
fastvideo.models.dits.hyworld.retrieval_context.calculate_fov_overlap_similarity ¶
calculate_fov_overlap_similarity(w2c_matrix_curr: Tensor, w2c_matrix_hist: Tensor, fov_h_deg: float = 105.0, fov_v_deg: float = 75.0, device=None, points_local=None) -> float
Calculate the Field-of-View (FOV) overlap similarity between two W2C poses using Monte Carlo sampling.
Similarity = (Number of points in Curr_FOV ∩ Hist_FOV) / (Number of points in Curr_FOV).
:param w2c_matrix_curr: The (4, 4) W2C matrix for the current frame. :param w2c_matrix_hist: The (4, 4) W2C matrix for the historical frame. :param num_samples, radius, fov_h_deg, fov_v_deg: Sampling and FOV parameters. :return: The overlap ratio (a float between 0.0 and 1.0).
Source code in fastvideo/models/dits/hyworld/retrieval_context.py
fastvideo.models.dits.hyworld.retrieval_context.generate_points_in_sphere ¶
Uniformly sample points within a sphere of a specified radius.
:param n_points: The number of points to generate. :param radius: The radius of the sphere. :return: A tensor of shape (n_points, 3), representing the (x, y, z) coordinates of the points.
Source code in fastvideo/models/dits/hyworld/retrieval_context.py
fastvideo.models.dits.hyworld.retrieval_context.is_inside_fov_3d_hv ¶
is_inside_fov_3d_hv(points: Tensor, center: Tensor, center_pitch: Tensor, center_yaw: Tensor, fov_half_h: Tensor, fov_half_v: Tensor) -> Tensor
Check whether points are inside a 3D view frustum defined by a center coordinate, pitch angle, and yaw angle.
:param points: Tensor of shape (N, 3) or (N, B, 3) representing the coordinates of the sampled points. :param center: Tensor of shape (3) or (B, 3) representing the camera center coordinates. :param center_pitch: Tensor of shape (1) or (B) representing the pitch angle of center view direction. :param center_yaw: Tensor of shape (1) or (B) representing the yaw angle of the center view direction. :param fov_half_h: The horizontal half field-of-view angle (in degrees). :param fov_half_v: The vertical half field-of-view angle (in degrees). :return: Boolean tensor of shape (N) or (N, B), indicating whether each point is inside the FOV.
Source code in fastvideo/models/dits/hyworld/retrieval_context.py
fastvideo.models.dits.hyworld.retrieval_context.rotation_matrix_to_angles ¶
rotation_matrix_to_angles(R: Tensor) -> Tuple[Tensor, Tensor]
Estimate the Pitch and Yaw angles from a 3x3 rotation matrix R in the camera coordinate system.
Assumed Camera Coordinate System: X=Right, Y=Up, Z=Backward (or NeRF style: X=Right, Y=Down, Z=Forward). Here we adopt the common Computer Vision convention: Z-axis is Forward.
Note: The angle calculations here are directly based on the conventions of your is_inside_fov_3d_hv function: - Yaw/Azimuth angle is in the XZ plane (atan2(x, z)). - Pitch/Elevation angle is relative to the horizontal plane (atan2(y, sqrt(x^2 + z^2))).
For the third column R[:, 2] of the W2C matrix R (the direction of the World Z-axis in the Camera frame), this typically corresponds to the direction the camera is looking (the representation of the world Z-axis in the camera frame).
To simplify and match your is_inside_fov logic, we directly use the camera's Z-axis vector: Camera Z-axis direction in World Frame (Forward Vector): fwd = R_w2c_inv @ [0, 0, 1] More simply, the Z-axis vector of the C2W matrix is the camera's forward vector in the world frame. C2W = W2C_inv
Source code in fastvideo/models/dits/hyworld/retrieval_context.py
fastvideo.models.dits.hyworld.retrieval_context.select_aligned_memory_frames ¶
select_aligned_memory_frames(w2c_list: List[ndarray], current_frame_idx: int, memory_frames: int, temporal_context_size: int, pred_latent_size: int, pos_weight: float = 1.0, ang_weight: float = 1.0, device=None, points_local=None) -> List[int]
Selects memory and context frames for a given frame based on a four-frame segment distance calculation.
:param w2c_list: List of all N 4x4 World-to-Camera (W2C) extrinsic matrices (np.ndarray). :param current_frame_idx: The index of the current frame to be processed. :param memory_frames: The total number of memory frames to select. :param context_size: The total number of context frames to select. :param pos_weight: The weight applied to the spatial (position) distance component. :param ang_weight: The weight applied to the angular distance component.
:return: List[int]: A list containing the indices of the selected memory frames and context frames.
Source code in fastvideo/models/dits/hyworld/retrieval_context.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |