mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
Integrating WebRTC into viewer (#73)
* restructuring for webrtc integration * some webrtc code but not working * webrtc connects when muted * the flag is real! * updating camera in websocket bridge. moved webrtc to existing websocket connection instead of http request. need to change video track * rudimentary adding real-time imaging * added free TURN server so code works everywhere * slow rendering works during training with the viewer * fix tensor device and update default model save dir * forgot to include trainer updates * removing some code that isn't needed * quick fix to bins. not the most accurate however * cleaned up code and added some config logic * black * adding license Co-authored-by: evonneng <evonne_ng@berkeley.edu>
This commit is contained in:
1 parent
e507c97e3e
commit
bf13ed3cf3
28 files changed
+8923
-917
No files matched your search
@@ -0,0 +1,51 @@
|
||||
# Copyright 2022 The Plenoptix Team. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
|
||||
def get_chunks(lst, num_chunks=None, size_of_chunk=None):
|
||||
"""Returns list of n elements, constaining a sublist."""
|
||||
if num_chunks:
|
||||
assert not size_of_chunk
|
||||
size = len(lst) // num_chunks
|
||||
if size_of_chunk:
|
||||
assert not num_chunks
|
||||
size = size_of_chunk
|
||||
chunks = []
|
||||
for i in range(0, len(lst), size):
|
||||
chunks.append(lst[i : i + size])
|
||||
return chunks
|
||||
|
||||
|
||||
def get_intrinsics_matrix_and_camera_to_world_h(camera_object, image_height):
|
||||
"""Returns the camera intrinsics matrix and the camera to world homogeneous matrix.
|
||||
Args:
|
||||
camera_object: a Camera object.
|
||||
image_size: the size of the image (height, width)
|
||||
"""
|
||||
# intrinsics
|
||||
fov = camera_object["fov"]
|
||||
aspect = camera_object["aspect"]
|
||||
image_width = aspect * image_height
|
||||
pp_w = image_width / 2.0
|
||||
pp_h = image_height / 2.0
|
||||
focal_length = pp_h / np.tan(fov * (np.pi / 180.0) / 2.0)
|
||||
intrinsics_matrix = torch.tensor([[focal_length, 0, pp_w], [0, focal_length, pp_h], [0, 0, 1]]).float()
|
||||
|
||||
# extrinsics
|
||||
camera_to_world_h = torch.tensor(get_chunks(camera_object["matrix"], size_of_chunk=4)).T.float()
|
||||
|
||||
return intrinsics_matrix, camera_to_world_h
|
||||
Reference in new issue
Block a user