Xharlie / pointnerf

Point-NeRF: Point-based Neural Radiance Fields
Other
1.1k stars 128 forks source link

How to export point cloud? #58

Open callzhang opened 2 years ago

callzhang commented 2 years ago

Hi,

Is there a way to convert the model to a point cloud representation?

Thanks!

Derek

satyajitghana commented 1 year ago

There's a save_points function in visualizer, i think we could use that

def save_points(xyz, dir, total_steps):
    if xyz.ndim < 3:
        xyz = xyz[None, ...]
    os.makedirs(dir, exist_ok=True)
    for i in range(xyz.shape[0]):
        if isinstance(total_steps,str):
            filename = 'step-{}-{}.txt'.format(total_steps, i)
        else:
            filename = 'step-{:04d}-{}.txt'.format(total_steps, i)
        filepath = os.path.join(dir, filename)
        np.savetxt(filepath, xyz[i, ...].reshape(-1, xyz.shape[-1]), delimiter=";")
Youngju-Na commented 1 year ago

Hi! Thanks or asking this question. On top of this question, I have one more question. Does anybody know why saving the first three elements of features concatenated with xyz?

def save_neural_points(self, total_steps, xyz, features, data, save_ref=0):
        if features is None:
            if torch.is_tensor(xyz):
                # xyz = xyz.detach().cpu().numpy()
                xyz = xyz.detach().cpu().numpy()
            save_points(xyz, self.point_dir, total_steps)
        elif features.shape[-1] == 9:
            pnt_lst = []
            for i in range(0,3):
                points = torch.cat([xyz, features[0, ..., i*3:i*3+3] * 255], dim=-1)
                if torch.is_tensor(points):
                    # xyz = xyz.detach().cpu().numpy()
                    points = points.detach().cpu().numpy()
                pnt_lst.append(points)
            save_points(np.stack(pnt_lst,axis=0), self.point_dir, total_steps)
        else:
            points = torch.cat([xyz, features[0, ..., :3] * 255], dim=-1)
            if torch.is_tensor(points):
                # xyz = xyz.detach().cpu().numpy()
                points = points.detach().cpu().numpy()
            save_points(points, self.point_dir, total_steps)
AbrarZShahriar commented 1 year ago

Has anyone extracted the point cloud with color info?