MCPcopy
hub / github.com/zju3dv/4K4D / get_pulsar_camera_params

Function get_pulsar_camera_params

easyvolcap/utils/fcds_utils.py:108–194  ·  view source on GitHub ↗
(
    R: torch.Tensor,
    tvec: torch.Tensor,
    camera_matrix: torch.Tensor,
    image_size: torch.Tensor,
    znear: float = 0.1,
)

Source from the content-addressed store, hash-verified

106
107
108def get_pulsar_camera_params(
109 R: torch.Tensor,
110 tvec: torch.Tensor,
111 camera_matrix: torch.Tensor,
112 image_size: torch.Tensor,
113 znear: float = 0.1,
114) -> torch.Tensor:
115 assert len(camera_matrix.size()) == 3, "This function requires batched inputs!"
116 assert len(R.size()) == 3, "This function requires batched inputs!"
117 assert len(tvec.size()) in (2, 3), "This function reuqires batched inputs!"
118
119 # Validate parameters.
120 image_size_wh = image_size.to(R).flip(dims=(1,))
121 assert torch.all(
122 image_size_wh > 0
123 ), "height and width must be positive but min is: %s" % (
124 str(image_size_wh.min().item())
125 )
126 assert (
127 camera_matrix.size(1) == 3 and camera_matrix.size(2) == 3
128 ), "Incorrect camera matrix shape: expected 3x3 but got %dx%d" % (
129 camera_matrix.size(1),
130 camera_matrix.size(2),
131 )
132 assert (
133 R.size(1) == 3 and R.size(2) == 3
134 ), "Incorrect R shape: expected 3x3 but got %dx%d" % (
135 R.size(1),
136 R.size(2),
137 )
138 if len(tvec.size()) == 2:
139 tvec = tvec.unsqueeze(2)
140 assert (
141 tvec.size(1) == 3 and tvec.size(2) == 1
142 ), "Incorrect tvec shape: expected 3x1 but got %dx%d" % (
143 tvec.size(1),
144 tvec.size(2),
145 )
146 # Check batch size.
147 batch_size = camera_matrix.size(0)
148 assert R.size(0) == batch_size, "Expected R to have batch size %d. Has size %d." % (
149 batch_size,
150 R.size(0),
151 )
152 assert (
153 tvec.size(0) == batch_size
154 ), "Expected tvec to have batch size %d. Has size %d." % (
155 batch_size,
156 tvec.size(0),
157 )
158 # Check image sizes.
159 image_w = image_size_wh[0, 0]
160 image_h = image_size_wh[0, 1]
161 assert torch.all(
162 image_size_wh[:, 0] == image_w
163 ), "All images in a batch must have the same width!"
164 assert torch.all(
165 image_size_wh[:, 1] == image_h

Callers 4

render_pulsarMethod · 0.90
test_pulsar_renderingFunction · 0.90

Calls 2

matrix_to_rotation_6dFunction · 0.85

Tested by 3

test_pulsar_renderingFunction · 0.72