Replies: 2 comments 1 reply
-
@destoswa Add a small reproducible code using available sample pcd from http://www.open3d.org/docs/latest/tutorial/data/index.html#pointcloud. It will allow me or others to quickly test. |
Beta Was this translation helpful? Give feedback.
-
Okay so while writing a demo, I found the problem^^ So the problem that I had was that when the function Regarding the down sampling, I simply used the function Following is the working demo: import open3d as o3d
import numpy as np
import random
def main():
device = o3d.core.Device('CPU:0')
dtype = o3d.core.float32
num_duplicates = 50
num_downsamp = 50
# load pcd
pcdt = o3d.t.io.read_point_cloud('sample.pcd')
# remove duplicates
point_set, idx = np.unique(pcdt.point['positions'].numpy(), axis=0, return_index=True)
intensities = pcdt.point['intensity'].numpy()[idx].reshape(-1, 1)
pcdt.point['positions'] = o3d.core.Tensor(point_set, dtype, device)
pcdt.point['intensity'] = o3d.core.Tensor(intensities, dtype, device)
# create copies
pcdt_up = pcdt.clone()
pcdt_down = pcdt.clone()
# Upsample
data = np.concatenate((pcdt.point['positions'].numpy(), pcdt.point['intensity'].numpy()), axis=1)
lst_duplicates = random.sample(range(data.shape[0]), num_duplicates) # find a list of points that are going to be duplicated
for el in lst_duplicates: # duplicate the points
data = np.concatenate((data, data[el, :].reshape((1, -1))), axis=0)
# update PointCloud and save file
pcdt_up.point['positions'] = o3d.core.Tensor(data[:, :-1], dtype, device)
pcdt_up.point['intensity'] = o3d.core.Tensor(data[:,-1].reshape(-1,1), dtype, device)
o3d.t.io.write_point_cloud('sample_up.pcd', pcdt_up, write_ascii=True)
# Downsample
data = pcdt.farthest_point_down_sample(num_downsamp).point['positions'].numpy()
intensities = pcdt.point['intensity'].numpy()
old_pos = pcdt.point['positions'].numpy()
mask = (old_pos == data[:, None]).all(2).any(0) # find which of the original pos has been kept
intensities = intensities[mask] # apply the mask to keep only the intensities of the kept pos
# update PointCloud and save file
pcdt_down.point['positions'] = o3d.core.Tensor(data, dtype, device)
pcdt_down.point['intensity'] = o3d.core.Tensor(intensities, dtype, device)
o3d.t.io.write_point_cloud('sample_down.pcd', pcdt_down, write_ascii=True)
if __name__ == '__main__':
main() Thank you very much for making me create this demo, this is how I found the solution! |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am having an issue. As said in the title, I am trying to upsample or downsample pcd files to a fixed size (number of points). The pickle is that I want to do that while keeping the intensity field.
First of all, in order to be able to access the intensity field, I load the pcd file through
o3d.t.io.read_point_cloud(filename)
Downsampling:
I am currently doing the following:
However, it only returns a PointCloud object with x,y,z fields.
Upsampling
I am copying the fields
pcdt.point['positions']
andpcdt.point['intensity']
into a numpy array of shape (N,4) and upsample it into an array of shape (N_wanted,4) and then reset the corresponding fields with the new values.By doing this, Open3D warn me that it drops some fields in the process, however it keeps the fields that I want.
The problem comes when I want to write this new field into a .csv file while using the following function:
It write the file but drops the intensity. I don't know why since if I use it on the pcdt object before upsampling (and dropping the unwanted fields), it keeps all the fields in the new file.
I hope that I developed enough my situation. If not, just ask for complementary information :)
Thank you for your help!
PS: and I hope that I am not writing this in the wrong place (first time using this forum)
Beta Was this translation helpful? Give feedback.
All reactions