CameraParameter
Inheritance diagram
- class xrfeitoria.camera.camera_parameter.CameraParameter(K: List | ndarray, R: List | ndarray, T: List | ndarray, convention: str = 'opencv', world2cam: bool = False)[source]
Camera parameter class for pinhole camera model.
Inherit from XRPrimer.
- ClassName(self: xrprimer_cpp.camera.BaseCameraParameter) str
- LoadFile(filename: str) bool
Load camera name and parameters from a dumped json file.
- Parameters:
filename (str) – Path to the dumped json file.
- Returns:
bool – True if load succeed.
- SaveFile(filename: str) bool
Dump camera name and parameters to a json file.
- Parameters:
filename (str) – Path to the dumped json file.
- Returns:
bool – True if save succeed.
- __init__(K: List | ndarray, R: List | ndarray, T: List | ndarray, convention: str = 'opencv', world2cam: bool = False)[source]
A camera parameter class for pinhole camera model.
- Parameters:
K (Union[list, np.ndarray]) – Nested list of float32, 4x4 or 3x3 K mat.
R (Union[list, np.ndarray]) – Nested list of float32, 3x3 rotation mat.
T (Union[list, np.ndarray, None]) – List of float32, T vector.
convention (str, optional) – Convention name of this camera. Defaults to ‘opencv’.
world2cam (bool, optional) – Whether the R, T transform points from world space to camera space. Defaults to True.
- clone() CameraParameter [source]
Clone a new CameraParameter instance like self.
- Returns:
CameraParameter
- convert_convention(dst: str)[source]
Convert the convention of this camera parameter. In-place.
- Parameters:
dst (str) – The name of destination convention. One of [‘opencv’, ‘blender’, ‘unreal’].
- dump(filename: str) None
Dump camera name and parameters to a json file.
- Parameters:
filename (str) – Path to the dumped json file.
- Raises:
RuntimeError – Fail to dump a json file.
- classmethod from_bin(file: str | Path) CameraParameter [source]
Construct a camera parameter data structure from a binary file.
- Parameters:
file (PathLike) – Path to the dumped binary file.
- Returns:
CameraParameter – An instance of CameraParameter class.
- classmethod from_dict(data: dict) CameraParameter [source]
Construct a camera parameter data structure from a dict.
- Parameters:
data (dict) – The camera parameter data.
- Returns:
CameraParameter – An instance of CameraParameter class.
- classmethod from_unreal_convention(location: Tuple[float, float, float], rotation: Tuple[float, float, float], fov: float, image_size: Tuple[int, int]) CameraParameter [source]
Converts camera parameters from Unreal Engine convention to CameraParameter object.
- Parameters:
location (Vector) – The camera location in Unreal Engine convention.
rotation (Vector) – The camera rotation in Unreal Engine convention.
fov (float) – The camera field of view in degrees.
image_size (Tuple[int, int]) – The size of the camera image in pixels (width, height).
- Returns:
CameraParameter – The converted camera parameters.
- classmethod fromfile(file: str | Path) CameraParameter [source]
Construct a camera parameter data structure from a json file.
- Parameters:
filename (PathLike) – Path to the dumped json file.
- Returns:
CameraParameter – An instance of CameraParameter class.
- get_extrinsic() List [source]
Get the camera matrix of RT.
- Returns:
List – A list of float32, 3x4 RT mat.
- get_extrinsic_r() list
Get extrinsic rotation matrix.
- Returns:
list – Nested list of float32, 3x3 R mat.
- get_extrinsic_t() list
Get extrinsic translation vector.
- Returns:
list – Nested list of float32, T vec of length 3.
- get_intrinsic(k_dim: int = 3) list
Get intrinsic K matrix.
- Parameters:
k_dim (int, optional) – If 3, returns a 3x3 mat. Else if 4, returns a 4x4 mat. Defaults to 3.
- Raises:
ValueError – k_dim is neither 3 nor 4.
- Returns:
list – Nested list of float32, 4x4 or 3x3 K mat.
- get_projection_matrix() List [source]
Get the camera matrix of
K@RT
.- Returns:
List – A list of float32, 3x4
K@RT
mat.
- intrinsic33() ndarray
Get an intrinsic matrix in shape (3, 3).
- Returns:
ndarray – An ndarray of intrinsic matrix.
- inverse_extrinsic() None
Inverse the direction of extrinsics, between world to camera and camera to world.
- load(filename: str) None
Load camera name and parameters from a dumped json file.
- Parameters:
filename (str) – Path to the dumped json file.
- Raises:
FileNotFoundError – File not found at filename.
ValueError – Content in filename is not correct.
- set_KRT(K: list | ndarray | None = None, R: list | ndarray | None = None, T: list | ndarray | None = None, world2cam: bool | None = None) None
Set K, R to matrix and T to vector.
- Parameters:
K (Union[list, np.ndarray, None]) – Nested list of float32, 4x4 or 3x3 K mat. Defaults to None, intrisic will not be changed.
R (Union[list, np.ndarray, None]) – Nested list of float32, 3x3 R mat. Defaults to None, extrisic_r will not be changed.
T (Union[list, np.ndarray, None]) – List of float32, T vector. Defaults to None, extrisic_t will not be changed.
world2cam (Union[bool, None], optional) – Whether the R, T transform points from world space to camera space. Defaults to None, self.world2cam will not be changed.
- set_intrinsic(mat3x3: list | ndarray | None = None, width: int | None = None, height: int | None = None, fx: float | None = None, fy: float | None = None, cx: float | None = None, cy: float | None = None, perspective: bool = True) None
Set the intrinsic of a camera. Note that mat3x3 has a higher priority than fx, fy, cx, cy.
- Parameters:
mat3x3 (list, optional) – A nested list of intrinsic matrix, in shape (3, 3). If mat is given, fx, fy, cx, cy will be ignored. Defaults to None.
width (int) – Width of the screen.
height (int) – Height of the screen.
fx (float, optional) – Focal length. Defaults to None.
fy (float, optional) – Focal length. Defaults to None.
cx (float, optional) – Camera principal point. Defaults to None.
cy (float, optional) – Camera principal point. Defaults to None.
perspective (bool, optional) – Whether it is a perspective camera, if not, it’s orthographics. Defaults to True.
- set_resolution(height: int, width: int) None
Set resolution of the camera.
- Parameters:
height (int) – Height of the screen.
width (int) – Width of the screen.
- property convention
str
- Type:
transform convention, default is opencv
- property extrinsic: ndarray[Any, dtype[float32]]
Get the extrinsic matrix of RT.
- Returns:
ndarray – An ndarray of float32, 3x4 RT mat.
- property extrinsic_r
numpy.ndarray[numpy.float32[3, 3]] or list
- Type:
camera extrinsics R
- property extrinsic_t
numpy.ndarray[numpy.float32[3, 1]] or list
- Type:
camera extrinsics T
- property height
int
- Type:
camera image height
- property intrinsic
numpy.ndarray[numpy.float32[4, 4]] or list
- Type:
camera intrinsic (4x4)
- property name
camera tag name
- property projection_matrix: ndarray[Any, dtype[float32]]
Get the camera matrix of
K@RT
.- Returns:
ndarray – An ndarray of float32, 3x4
K@RT
mat.
- property width
int
- Type:
camera image width
- property world2cam
bool
- Type:
world to camera flag