Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyida committed May 9, 2024
1 parent d56e602 commit 8ea5474
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 88 deletions.
2 changes: 1 addition & 1 deletion configs/neus-hmvs-eagle-wbg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ model:
output_activation: none
n_neurons: 64
n_hidden_layers: 1
sphere_init: false # true
sphere_init: true
sphere_init_radius: 0.5
weight_norm: true
max_imgs: ${dataset.max_imgs}
Expand Down
2 changes: 1 addition & 1 deletion datasets/colmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def setup(self, config, split):
import open3d as o3d
# NOTE: save the point cloud using point cloud
pcd = o3d.geometry.PointCloud()
mesh_init_path = os.path.join(self.config.root_dir, 'sparse/0/points3D.ply')
mesh_init_path = os.path.join(self.config.root_dir, 'sparse/0/points3D.obj')
if os.path.exists(mesh_init_path):
mesh_o3d = o3d.t.geometry.TriangleMesh.from_legacy(o3d.io.read_triangle_mesh(mesh_init_path))
else:
Expand Down
83 changes: 0 additions & 83 deletions datasets/hmvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,86 +123,12 @@ def setup(self, config, split):

all_images, all_vis_masks, all_fg_masks, all_depths, all_depth_masks, directions = [], [], [], [], [], []

<<<<<<< HEAD
import open3d as o3d
=======
print(colored('Remember to deal with the unique dimention of rear images', 'red'))
# Load point cloud which might be scanned
import open3d as o3d
if self.config.pcd_path is not None and self.config.pcd_path.endswith('.npz'):
pts3d = []
pts3d_frames = np.load(self.config.pcd_path, allow_pickle=True)['pointcloud'].item()
for id_pts, pts_frame in pts3d_frames.items():
pts3d.append(np.array(pts_frame))
pts3d = np.vstack(pts3d)[:, :3]
elif self.config.pcd_path is not None:
assert os.path.isfile(self.config.pcd_path)
pts3d = np.asarray(
o3d.io.read_point_cloud(self.config.pcd_path).points)
else:
print(colored('sparse point cloud not given', 'red'))
pts3d = []

if pts3d is not None:
# NOTE: save the point cloud using point cloud
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(pts3d)
pts3d = torch.from_numpy(pts3d).float()
mesh_dir = os.path.join(self.config.root_dir, 'mesh_exp')
os.makedirs(mesh_dir, exist_ok=True)
if not os.path.exists(os.path.join(mesh_dir, 'layout_pcd_gt.ply')):
# pcd = pcd.voxel_down_sample(voxel_size=0.002)
pcd.estimate_normals(
search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=20))
o3d.io.write_point_cloud(os.path.join(mesh_dir, 'layout_pcd_gt.ply'), pcd)
else:
pcd.normals = o3d.io.read_point_cloud(os.path.join(mesh_dir, 'layout_pcd_gt.ply')).normals


# Poisson surface on top of given GT points
mesh_poisson_path = os.path.join(mesh_dir, 'layout_mesh_ps.ply')
if not os.path.exists(mesh_poisson_path):
print(colored(
'[1] Extracting Poisson surface on top of given GT points',
'blue'))
with o3d.utility.VerbosityContextManager(
o3d.utility.VerbosityLevel.Debug) as cm:
# Poisson
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
pcd, depth=10, linear_fit=True)
o3d.io.write_triangle_mesh(mesh_poisson_path, mesh)
mesh_o3d = o3d.t.geometry.TriangleMesh.from_legacy(o3d.io.read_triangle_mesh(mesh_poisson_path))

# Poisson surface on top of given GT points
"""
mesh_bp_path = os.path.join(mesh_dir, 'layout_mesh_bp.ply')
if not os.path.exists(mesh_bp_path):
print(colored(
'[2] Extracting ball pivoting surface on top of given GT points',
'blue'))
distances = pcd.compute_nearest_neighbor_distance()
radius = np.max([1.5 * np.mean(distances), 0.02])
# estimate radius for rolling ball
mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(
pcd,
o3d.utility.DoubleVector([radius, radius * 2]))
o3d.io.write_triangle_mesh(mesh_poisson_path, mesh)
mesh_o3d = o3d.t.geometry.TriangleMesh.from_legacy(o3d.io.read_triangle_mesh(mesh_bp_path))
"""

# Create scene and add the mesh
scene = o3d.t.geometry.RaycastingScene()
scene.add_triangles(mesh_o3d)

>>>>>>> 30934cd3847c5804aa13584cdeb770bbe3b25d2c
pts_clt = o3d.geometry.PointCloud()
self.num_imgs = 0
self.num_cams = 1
for i, d in enumerate(all_c2w):
<<<<<<< HEAD
self.num_imgs += 1
=======
>>>>>>> 30934cd3847c5804aa13584cdeb770bbe3b25d2c
if self.split in ['train', 'val']:
idx_tmp = fns[i].replace(self.config.root_dir,
'')[1:].rfind('/')
Expand All @@ -222,10 +148,7 @@ def setup(self, config, split):
if isinstance(intrinsics[i], np.ndarray):
if 'img_wh' in self.config:
w, h = self.config.img_wh
<<<<<<< HEAD
self.factor = w / W
=======
>>>>>>> 30934cd3847c5804aa13584cdeb770bbe3b25d2c
else:
self.factor = 1.0 / self.config.img_downscale
w, h = int(W * self.factor), int(H * self.factor)
Expand All @@ -252,13 +175,7 @@ def setup(self, config, split):

img_wh = (w, h)
self.factor = w / W
<<<<<<< HEAD
fx = fy = intrinsic["f"] * self.factor
=======

fx = fy = intrinsic[
"f"] * self.factor # camdata[1].params[0] * self.factor
>>>>>>> 30934cd3847c5804aa13584cdeb770bbe3b25d2c
cx = intrinsic["cx"] * self.factor
cy = intrinsic["cy"] * self.factor

Expand Down
2 changes: 1 addition & 1 deletion systems/neus.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def export(self):
self.dataset.repose_s
# export with the original pose
vertices = np.asarray(mesh['v_pos'])
vertices *= self.dataset.repose_s.numpy()
vertices *= self.dataset.repose_s # .numpy()
vertices -= torch.squeeze(self.dataset.repose_t).repeat(vertices.shape[0], 1).numpy()
vertices = np.transpose(torch.inverse(self.dataset.repose_R).numpy() @ np.transpose(vertices))
mesh['v_pos'] = torch.tensor(vertices)
Expand Down
5 changes: 3 additions & 2 deletions utils/pose_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pyransac3d as pyrsc
import torch
import torch.nn.functional as F
import math

# get center
def get_center(pts):
Expand Down Expand Up @@ -166,7 +167,7 @@ def normalize_poses(poses,
# rescaling
if not cam_downscale:
# auto-scale with point cloud supervision
cam_downscale = pts.norm(p=2, dim=-1).max()
cam_downscale = pts.norm(p=2, dim=-1).max().numpy()
# auto-scale with camera positions
# cam_downscale = poses_norm[..., 3].norm(p=2, dim=-1).min()
poses_norm[..., 3] /= cam_downscale
Expand Down Expand Up @@ -208,7 +209,7 @@ def normalize_poses(poses,
# rescaling
if not cam_downscale:
# auto-scale with point cloud supervision
cam_downscale = pts.norm(p=2, dim=-1).max()
cam_downscale = pts.norm(p=2, dim=-1).max().numpy()
# auto-scale with camera positions
# cam_downscale = poses_norm[..., 3].norm(p=2, dim=-1).min()
poses_norm[..., 3] /= cam_downscale
Expand Down

0 comments on commit 8ea5474

Please sign in to comment.