mmagic.models.editors.eg3d.camera
¶
Module Contents¶
Classes¶
Base camera class. Sample camera position on sphere with specific |
|
Pre-defined camera class. Sample camera position in gaussian |
|
Pre-defined camera class. Sample camera position in uniform |
Functions¶
|
Calculate camera-to-world matrix from camera's forward vector, world |
Attributes¶
- class mmagic.models.editors.eg3d.camera.BaseCamera(horizontal_mean: Optional[float] = None, vertical_mean: Optional[float] = None, horizontal_std: Optional[float] = 0, vertical_std: Optional[float] = 0, look_at: VectorType = [0, 0, 0], fov: Optional[float] = None, focal: Optional[float] = None, up: VectorType = [0, 1, 0], radius: Optional[float] = 1, sampling_strategy: str = 'uniform')[source]¶
Bases:
object
Base camera class. Sample camera position on sphere with specific distribution (e.g., Gaussian, Uniform) and return camera-to-world matrix and intrinsics matrix.
- Parameters
horizontal_mean (Optional[float]) – Mean of the horizontal range in radian. Defaults to None.
vertical_mean (Optional[float]) – Mean of the vertical range in radian. Defaults to None.
horizontal_std (Optional[float]) – Standard deviation of the horizontal range in radian. Defaults to None.
vertical_std (Optional[float]) – Standard deviation of the vertical range in radian. Defaults to None.
look_at (Optional[List, torch.Tensor]) – The look at position of the camera. Defaults to None.
fov (Optional[float]) – The FOV (field-of-view) in degree. Defaults to None.
up (Optional[List, torch.Tensor]) – The up direction of the world coordinate. Defaults to None.
radius (Optional[float]) – Radius of the sphere. Defaults to None.
sampling_strategy (Optional[str]) – The sampling strategy (distribution) of the camera. Support ‘Uniform’ and ‘Gaussian’. Defaults to ‘Uniform’.
- _sample_in_range(mean: float, std: float, batch_size: int) torch.Tensor [source]¶
Sample value with specific mean and std.
- Parameters
mean (float) – Mean of the sampled value.
std (float) – Standard deviation of the sampled value.
batch_size (int) – The batch size of the sampled result.
- Returns
Sampled results.
- Return type
torch.Tensor
- sample_intrinsic(fov: Optional[float] = None, focal: Optional[float] = None, device: Optional[DeviceType] = None, batch_size: int = 1) torch.Tensor [source]¶
Sample intrinsic matrix.
- Parameters
fov (Optional[float], optional) – FOV (field of view) in degree. If not passed,
self.fov
will be used. Defaults to None.focal (Optional[float], optional) – Focal in pixel. If not passed,
self.focal
will be used. Defaults to None.batch_size (int) – The batch size of the output. Defaults to 1.
device (DeviceType, optional) – Device to put the intrinsic matrix. If not passed,
self.device
will be used. Defaults to None.
- Returns
Intrinsic matrix.
- Return type
torch.Tensor
- fov_to_intrinsic(fov: Optional[float] = None, device: DeviceType = None) torch.Tensor [source]¶
Calculate intrinsic matrix from FOV (field of view).
- Parameters
fov (Optional[float], optional) – FOV (field of view) in degree. If not passed,
self.fov
will be used. Defaults to None.device (DeviceType, optional) – Device to put the intrinsic matrix. If not passed,
self.device
will be used. Defaults to None.
- Returns
Intrinsic matrix.
- Return type
torch.Tensor
- focal_to_instrinsic(focal: Optional[float] = None, device: DeviceType = None) torch.Tensor [source]¶
Calculate intrinsic matrix from focal.
- Parameters
focal (Optional[float], optional) – Focal in degree. If not passed,
self.focal
will be used. Defaults to None.device (DeviceType, optional) – Device to put the intrinsic matrix. If not passed,
self.device
will be used. Defaults to None.
- Returns
Intrinsic matrix.
- Return type
torch.Tensor
- sample_theta(mean: float, std: float, batch_size: int) torch.Tensor [source]¶
Sampling the theta (yaw).
- Parameters
mean (float) – Mean of theta.
std (float) – Standard deviation of theta.
batch_size (int) – Target batch size of theta.
- Returns
Sampled theta.
- Return type
torch.Tensor
- sample_phi(mean: float, std: float, batch_size: int) torch.Tensor [source]¶
Sampling the phi (pitch). Unlike sampling theta, we uniformly sample phi on cosine space to release a spherical uniform sampling.
- Parameters
mean (float) – Mean of phi.
std (float) – Standard deviation of phi.
batch_size (int) – Target batch size of phi.
- Returns
Sampled phi.
- Return type
torch.Tensor
- sample_camera2world(h_mean: Optional[float] = None, v_mean: Optional[float] = None, h_std: Optional[float] = None, v_std: Optional[float] = None, look_at: VectorType = None, up: VectorType = None, radius: Optional[float] = None, batch_size: int = 1, device: Optional[str] = None) torch.Tensor [source]¶
Sample camera-to-world matrix with the passed condition.
- Parameters
h_mean (Optional[float], optional) – Mean of horizontal range in radian. Defaults to None.
v_mean (Optional[float], optional) – Mean of vertical range in radian. Defaults to None.
h_std (Optional[float], optional) – Standard deviation of horizontal in radian. Defaults to None.
v_std (Optional[float], optional) – Standard deviation of horizontal in radian. Defaults to None.
look_at (Optional[Tuple[list, torch.Tensor]], optional) – Look-at position. Defaults to None.
up (Optional[Tuple[list, torch.Tensor]], optional) – Up direction of the world coordinate. Defaults to None.
radius (Optional[float]) – Radius of the sphere. Defaults to None.
batch_size (int, optional) – Batch size of the results. Defaults to 1.
device (Optional[str], optional) – The target device of the results. Defaults to None.
- Returns
Sampled camera-to-world matrix.
- Return type
torch.Tensor
- interpolation_cam2world(num_images: int, h_mean: Optional[float] = None, v_mean: Optional[float] = None, h_std: Optional[float] = None, v_std: Optional[float] = None, look_at: VectorType = None, up: VectorType = None, radius: Optional[float] = None, batch_size: int = 1, device: Optional[str] = None) List[torch.Tensor] [source]¶
Interpolation camera original in spherical trajectory and return a list of camera-to-world matrix.
- Parameters
num_images (int) – The number of images in interpolation.
h_mean (Optional[float], optional) – Mean of horizontal range in radian. Defaults to None.
v_mean (Optional[float], optional) – Mean of vertical range in radian. Defaults to None.
h_std (Optional[float], optional) – Standard deviation of horizontal in radian. Defaults to None.
v_std (Optional[float], optional) – Standard deviation of horizontal in radian. Defaults to None.
look_at (Optional[Tuple[list, torch.Tensor]], optional) – Look-at position. Defaults to None.
up (Optional[Tuple[list, torch.Tensor]], optional) – Up direction of the world coordinate. Defaults to None.
radius (Optional[float]) – Radius of the sphere. Defaults to None.
batch_size (int, optional) – Batch size of the results. Defaults to 1.
device (Optional[str], optional) – The target device of the results. Defaults to None.
- Returns
List of sampled camera-to-world matrix.
- Return type
List[torch.Tensor]
- class mmagic.models.editors.eg3d.camera.GaussianCamera(horizontal_mean: Optional[float] = None, vertical_mean: Optional[float] = None, horizontal_std: Optional[float] = 0, vertical_std: Optional[float] = 0, look_at: List = [0, 0, 0], fov: Optional[float] = None, focal: Optional[float] = None, up: VectorType = [0, 1, 0], radius: Optional[float] = 1)[source]¶
Bases:
BaseCamera
Pre-defined camera class. Sample camera position in gaussian distribution.
- Parameters
horizontal_mean (Optional[float]) – Mean of the horizontal range in radian. Defaults to None.
vertical_mean (Optional[float]) – Mean of the vertical range in radian. Defaults to None.
horizontal_std (Optional[float]) – Standard deviation of the horizontal range in radian. Defaults to None.
vertical_std (Optional[float]) – Standard deviation of the vertical range in radian. Defaults to None.
look_at (Optional[List, torch.Tensor]) – The look at position of the camera. Defaults to None.
up (Optional[List, torch.Tensor]) – The up direction of the world coordinate. Defaults to None.
radius (Optional[float]) – Radius of the sphere. Defaults to None.
- class mmagic.models.editors.eg3d.camera.UniformCamera(horizontal_mean: Optional[float] = None, vertical_mean: Optional[float] = None, horizontal_std: Optional[float] = 0, vertical_std: Optional[float] = 0, look_at: List = [0, 0, 0], fov: Optional[float] = None, focal: Optional[float] = None, up: VectorType = [0, 1, 0], radius: Optional[float] = 1)[source]¶
Bases:
BaseCamera
Pre-defined camera class. Sample camera position in uniform distribution.
- Parameters
horizontal_mean (Optional[float]) – Mean of the horizontal range in radian. Defaults to None.
vertical_mean (Optional[float]) – Mean of the vertical range in radian. Defaults to None.
horizontal_std (Optional[float]) – Standard deviation of the horizontal range in radian. Defaults to None.
vertical_std (Optional[float]) – Standard deviation of the vertical range in radian. Defaults to None.
look_at (Optional[List, torch.Tensor]) – The look at position of the camera. Defaults to None.
up (Optional[List, torch.Tensor]) – The up direction of the world coordinate. Defaults to None.
radius (Optional[float]) – Radius of the sphere. Defaults to None.
- mmagic.models.editors.eg3d.camera.create_cam2world_matrix(forward_vector: torch.Tensor, origin: torch.Tensor, up: torch.Tensor) torch.Tensor [source]¶
Calculate camera-to-world matrix from camera’s forward vector, world origin and world up direction. The calculation is performed in right-hand coordinate system and the returned matrix is in homogeneous coordinates (shape like (bz, 4, 4)).
- Parameters
forward_vector (torch.Tensor) – The forward vector of the camera.
origin (torch.Tensor) – The origin of the world coordinate.
up (torch.Tensor) – The up direction of the world coordinate.
- Returns
Camera-to-world matrix.
- Return type
torch.Tensor