MCPcopy Create free account
hub / github.com/apple/ml-pointersect / generate_random_camera_poses

Function generate_random_camera_poses

plib/rigid_motion.py:571–683  ·  view source on GitHub ↗

Generate `n` random camera poses, all of them within a cone of angle of `max_angle` (in degree) (i.e., -max_angle, max_angle) pointing toward a random direction. The camera centers to the origin are within min_r to max_r. If `local_max_angle` = 0, the camera will point to a random

(
        n: int,
        max_angle: float,
        min_r: float,
        max_r: float,
        center_direction_w: T.List[float] = None,
        rng: np.random.RandomState = None,
        local_max_angle: float = 0.,
        rand_r: float = 0,
        origin_w: T.List[float] = None,  # (0., 0., 0.,),
        dtype: np.dtype = np.float32,
        method: str = 'random',
)

Source from the content-addressed store, hash-verified

569
570
571def generate_random_camera_poses(
572 n: int,
573 max_angle: float,
574 min_r: float,
575 max_r: float,
576 center_direction_w: T.List[float] = None,
577 rng: np.random.RandomState = None,
578 local_max_angle: float = 0.,
579 rand_r: float = 0,
580 origin_w: T.List[float] = None, # (0., 0., 0.,),
581 dtype: np.dtype = np.float32,
582 method: str = 'random',
583) -> T.List[np.ndarray]:
584 """
585 Generate `n` random camera poses, all of them within a cone of angle of `max_angle` (in degree)
586 (i.e., -max_angle, max_angle) pointing toward a random direction.
587 The camera centers to the origin are within min_r to max_r.
588
589 If `local_max_angle` = 0, the camera will point to a random point with a sphere with r=rand_r.
590
591 Args:
592 max_angle:
593 in degree. within the range of [0, 180.], if 180, covers the entire sphere.
594 center_direction_w:
595 the center direction of the cone. If None, randomly choose one.
596 local_max_angle:
597 A small random xyz rotation (in degree) for each camera
598 rand_r:
599 a box with radius `center_r` within which the camera will be looking at
600 origin_w:
601 the origin in the world coordinate where the camera is randomly placed.
602 If None, origin_w = (0, 0, 0,)
603 method:
604 'random'
605 """
606
607 np_dtype = sample_utils.get_np_dtype(dtype)
608 torch_dtype = sample_utils.get_np_dtype(dtype)
609
610 if rng is None:
611 rng = np.random
612
613 # we first assume the world coordinate's y axis and z axis are flipped.
614 # in order words, we have x to right, y to up, z to us.
615 # We will deal with it at the end.
616
617 if center_direction_w is None:
618 # randomly sample a center direction
619 d0 = get_random_direction(rng=rng) # (3,) float64
620 else:
621 d0 = np.array(center_direction_w, dtype=np.float64) # (3,) float64
622
623 # randomly sample within the cone centered at (0,0,1) and spanning theta degrees each direction
624 ds = get_random_direction_within_cone(
625 n=n,
626 theta=max_angle,
627 rng=rng,
628 method=method,

Callers

nothing calls this directly

Calls 6

get_random_directionFunction · 0.85
get_min_RFunction · 0.85
construct_coord_frameFunction · 0.85
RigidMotionClass · 0.85
homogeneous_matrixMethod · 0.80

Tested by

no test coverage detected