MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / generate_interpolated_path

Function generate_interpolated_path

utils/pose_utils.py:418–569  ·  view source on GitHub ↗

Creates a smooth spline path between input keyframe camera poses. Spline is calculated with poses in format (position, lookat-point, up-point). Args: poses: (n, 3, 4) array of input pose keyframes. n_interp: returned path will have n_interp * (n - 1) total poses. spline_degree: poly

(
    views,
    n_interp,
    spline_degree = 5,
    smoothness = 0.03,
    rot_weight = 0.1,
    lock_up = False,
    fixed_up_vector = None,
    lookahead_i = None,
    frames_per_colmap = None,
    const_speed = False,
    n_buffer = None,
    periodic = False,
    n_interp_as_total = False,
)

Source from the content-addressed store, hash-verified

416
417
418def generate_interpolated_path(
419 views,
420 n_interp,
421 spline_degree = 5,
422 smoothness = 0.03,
423 rot_weight = 0.1,
424 lock_up = False,
425 fixed_up_vector = None,
426 lookahead_i = None,
427 frames_per_colmap = None,
428 const_speed = False,
429 n_buffer = None,
430 periodic = False,
431 n_interp_as_total = False,
432):
433 """Creates a smooth spline path between input keyframe camera poses.
434
435 Spline is calculated with poses in format (position, lookat-point, up-point).
436 Args:
437 poses: (n, 3, 4) array of input pose keyframes.
438 n_interp: returned path will have n_interp * (n - 1) total poses.
439 spline_degree: polynomial degree of B-spline.
440 smoothness: parameter for spline smoothing, 0 forces exact interpolation.
441 rot_weight: relative weighting of rotation/translation in spline solve.
442 lock_up: if True, forced to use given Up and allow Lookat to vary.
443 fixed_up_vector: replace the interpolated `up` with a fixed vector.
444 lookahead_i: force the look direction to look at the pose `i` frames ahead.
445 frames_per_colmap: conversion factor for the desired average velocity.
446 const_speed: renormalize spline to have constant delta between each pose.
447 n_buffer: Number of buffer frames to insert at the start and end of the
448 path. Helps keep the ends of a spline path straight.
449 periodic: make the spline path periodic (perfect loop).
450 n_interp_as_total: use n_interp as total number of poses in path rather than
451 the number of poses to interpolate between each input.
452
453 Returns:
454 Array of new camera poses with shape (n_interp * (n - 1), 3, 4), or
455 (n_interp, 3, 4) if n_interp_as_total is set.
456 """
457 poses = []
458 for view in views:
459 tmp_view = np.eye(4)
460 tmp_view[:3] = np.concatenate([view.R.T, view.T[:, None]], 1)
461 tmp_view = np.linalg.inv(tmp_view)
462 tmp_view[:, 1:3] *= -1
463 poses.append(tmp_view)
464 poses = np.stack(poses, 0)
465
466 def poses_to_points(poses, dist):
467 """Converts from pose matrices to (position, lookat, up) format."""
468 pos = poses[:, :3, -1]
469 lookat = poses[:, :3, -1] - dist * poses[:, :3, 2]
470 up = poses[:, :3, -1] + dist * poses[:, :3, 1]
471 return np.stack([pos, lookat, up], 1)
472
473 def points_to_poses(points):
474 """Converts from (position, lookat, up) format to pose matrices."""
475 poses = []

Callers

nothing calls this directly

Calls 6

sampleFunction · 0.90
insert_buffer_posesFunction · 0.85
remove_buffer_posesFunction · 0.85
poses_to_pointsFunction · 0.70
interpFunction · 0.70
points_to_posesFunction · 0.70

Tested by

no test coverage detected