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

Function encode_easyvolcap_stereo_imgs

easyvolcap/utils/unity_utils.py:298–316  ·  view source on GitHub ↗

Encode the easyvolcap rendered stereo image pairs using `turbojpeg`, which is the fastest encoding method I know so far, the encoded bytes stream is in structured as 4 bytes(encoded bytes number of the left image) + encoded left image + encoded right image. Args:

(tensor_left: torch.Tensor, tensor_right: torch.Tensor)

Source from the content-addressed store, hash-verified

296
297
298def encode_easyvolcap_stereo_imgs(tensor_left: torch.Tensor, tensor_right: torch.Tensor):
299 """ Encode the easyvolcap rendered stereo image pairs using `turbojpeg`, which is
300 the fastest encoding method I know so far, the encoded bytes stream is in structured
301 as 4 bytes(encoded bytes number of the left image) + encoded left image + encoded
302 right image.
303 Args:
304 tensor_left: (torch.Tensor), (B, H, W, 4), rendered left eye RGBA image, already detach and on cpu.
305 tensor_right: (torch.Tensor), (B, H, W, 4), rendered right eye RGBA image, already detach and on cpu.
306 Returns:
307 bytes stream including 4 bytes of left encoded image, encoded left and right image.
308 """
309 jpeg = turbojpeg.TurboJPEG()
310 # Encode the rendered images for left eye and right respectively
311 bytes_left = jpeg.encode(tensor_left.numpy(), quality=70, pixel_format=turbojpeg.TJPF_RGBA)
312 bytes_right = jpeg.encode(tensor_right.numpy(), quality=70, pixel_format=turbojpeg.TJPF_RGBA)
313 # Need to tell C++ the length of the first encoded image to avoid unnecessary decoding
314 length_left = struct.pack('i', len(bytes_left))
315 length_right = struct.pack('i', len(bytes_right))
316 return length_left + length_right + bytes_left + bytes_right
317
318
319def log_stereo_params(w2cL, w2cR, KL, KR):

Callers

nothing calls this directly

Calls 2

numpyMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected