Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nerfcapture2nerf.py to allow to run it without depth info #1533

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/neural-graphics-primitives/testbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ class Testbed {

#ifdef NGP_PYTHON
void set_image(int frame_idx, pybind11::array_t<float> img, pybind11::array_t<float> depth_img, float depth_scale);
void set_image_no_depth(int frame_idx, pybind11::array_t<float> img);
#endif

void reset_camera_extrinsics();
Expand Down
5 changes: 4 additions & 1 deletion scripts/nerfcapture2nerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class NeRFCaptureFrame(idl.IdlStruct, typename="NeRFCaptureData.NeRFCaptureFrame
# ==================================================================================================

def set_frame(testbed, frame_idx: int, rgb: np.ndarray, depth: np.ndarray, depth_scale: float, X_WV: np.ndarray, fx: float, fy: float, cx: float, cy: float):
testbed.nerf.training.set_image(frame_idx = frame_idx, img=rgb, depth_img=depth, depth_scale=depth_scale*testbed.nerf.training.dataset.scale)
if depth != None:
testbed.nerf.training.set_image(frame_idx = frame_idx, img=rgb, depth_img=depth, depth_scale=depth_scale*testbed.nerf.training.dataset.scale)
else:
testbed.nerf.training.set_image_no_depth(frame_idx = frame_idx, img=rgb)
testbed.nerf.training.set_camera_extrinsics(frame_idx=frame_idx, camera_to_world=X_WV)
testbed.nerf.training.set_camera_intrinsics(frame_idx=frame_idx, fx=fx, fy=fy, cx=cx, cy=cy)

Expand Down
18 changes: 18 additions & 0 deletions src/python_api.cu
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ void Testbed::Nerf::Training::set_image(int frame_idx, pybind11::array_t<float>
dataset.set_training_image(frame_idx, {(int)img_buf.shape[1], (int)img_buf.shape[0]}, (const void*)img_buf.ptr, (const float*)depth_buf.ptr, depth_scale, false, EImageDataType::Float, EDepthDataType::Float);
}

void Testbed::Nerf::Training::set_image_no_depth(int frame_idx, pybind11::array_t<float> img) {
if (frame_idx < 0 || frame_idx >= dataset.n_images) {
throw std::runtime_error{"Invalid frame index"};
}

py::buffer_info img_buf = img.request();

if (img_buf.ndim != 3) {
throw std::runtime_error{"image should be (H,W,C) where C=4"};
}

if (img_buf.shape[2] != 4) {
throw std::runtime_error{"image should be (H,W,C) where C=4"};
}

dataset.set_training_image(frame_idx, {(int)img_buf.shape[1], (int)img_buf.shape[0]}, (const void*)img_buf.ptr, nullptr, -1.0, false, EImageDataType::Float, EDepthDataType::Float);
}

void Testbed::override_sdf_training_data(py::array_t<float> points, py::array_t<float> distances) {
py::buffer_info points_buf = points.request();
py::buffer_info distances_buf = distances.request();
Expand Down