MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / __init__

Method __init__

detrsmpl/core/cameras/cameras.py:22–129  ·  view source on GitHub ↗

Initialize your cameras with `build_cameras` following: 1): provide `K`, `R`, `T`, `resolution`/`image_size`, `in_ndc` directly. `K` should be shape of (N, 3, 3) or (N, 4, 4). `R` should be shape of (N, 3, 3). `T` should be shape of (N, 3).

(self, **kwargs)

Source from the content-addressed store, hash-verified

20class MMCamerasBase(cameras.CamerasBase):
21 """Inherited from Pytorch3D CamerasBase and provide some new functions."""
22 def __init__(self, **kwargs) -> None:
23 """Initialize your cameras with `build_cameras` following:
24
25 1): provide `K`, `R`, `T`, `resolution`/`image_size`, `in_ndc`
26 directly.
27 `K` should be shape of (N, 3, 3) or (N, 4, 4).
28 `R` should be shape of (N, 3, 3).
29 `T` should be shape of (N, 3).
30 2): if `K` is not provided, will use `get_default_projection_matrix`
31 to generate K from camera intrinsic parameters.
32 E.g., you can pass `focal_length`, `principal_point` for
33 perspective camers.
34 If these args are not provided, will use default values.
35 3): if `R` is not provided, will use Identity matrix as default.
36 4): if `T` is not provided, will use zeros matrix as default.
37 5): `convention` means your source parameter camera convention.
38 This mainly depends on how you get the matrixs. E.g., you get the
39 `K` `R`, `T` by calibration with opencv, you should set
40 `convention = opencv`. To figure out your camera convention,
41 please see the definition of its extrinsic and intrinsic matrixs.
42 For projection and rendering, the matrixs will be converted to
43 `pytorch3d` finally since the `transforms3d` called in rendering
44 and projection are defined as `pytorch3d` convention.
45 6): `image_size` equals `resolution`.
46 7): `in_ndc` could be set for 'PerspectiveCameras' and
47 'OrthographicCameras', other cameras are fixed for this arg.
48 `in_ndc = True` means your projection matrix is defined as `camera
49 space to NDC space`. Under this cirecumstance you need to set
50 `image_size` or `resolution` (they are equal) when you need to do
51 `transform_points_screen`. You can also override resolution
52 in `transform_points_screen` function.
53 `in_ndc = False` means your projections matrix is defined as
54 `cameras space to screen space`. Under this cirecumstance you do
55 not need to set `image_size` or `resolution` (they are equal) when
56 you need to do `transform_points_screen` since the projection
57 matrix is defined as view space to screen space.
58 """
59 for k in kwargs:
60 if isinstance(kwargs.get(k), np.ndarray):
61 kwargs.update({k: torch.Tensor(kwargs[k])})
62 convention = kwargs.pop('convention', 'pytorch3d').lower()
63 in_ndc = kwargs.pop('in_ndc', kwargs.get('_in_ndc'))
64 kwargs.update(_in_ndc=in_ndc)
65 is_perspective = kwargs.get('_is_perspective')
66 kwargs.pop('is_perspective', None)
67
68 image_size = kwargs.get('image_size', kwargs.get('resolution', None))
69
70 if image_size is not None:
71 if isinstance(image_size, (int, float)):
72 image_size = (image_size, image_size)
73 if isinstance(image_size, (tuple, list)):
74 image_size = torch.Tensor(image_size)
75 if isinstance(image_size, torch.Tensor):
76 if image_size.numel() == 1:
77 image_size = image_size.repeat(2)
78 image_size = image_size.view(-1, 2)
79

Callers 5

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 4

convert_camera_matrixFunction · 0.90
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected