Save an icp registered pointclouds as one open3d.geometry.PointCloud variable
Hi!
I have two pointclouds which I can register using icp and it works fine as shown in this Open3D tutorial. However, to see how the registered pointcloud is, I always have to call the draw_registration_result(source, destination, transformation) function with parameters - source pointcloud, target pointcloud and ICP transformation matrix. It would be really handy if it is possible to access the registered pointcloud as a single open3d.geometry.PointCloud variable for further use.
If I understood properly, the draw_registration_result(source, destination, transformation) function transforms the source to the target using the transformation matrix from the ICP registration function and then visualizes both pointclouds (as List[open3d.geometry.Geometry]).
I was wondering if there is any way to save the resulting pointcloud that we visualize from the draw_registration_result(source, destination, transformation) function, to one single pointcloud variable.
Essentially, I want one single pointcloud from the viewpoint of the target pointcloud, and includes both - the target and the ICP transformed source points.
I am trying to do this and if there is any existing way to achieve this, please help me out. If not, could this be considered as a feature request?
Thanks!
Edit: Turns out we can simply add both pointclouds with the + operator and it works fine.
do you find any method to save two combined point clouds in one point cloud after registration ?
Yep. It was a simple + operator.
Transform the source pointcloud with ICP transformation matrix and save it in one pointcloud variable (transformed_source), add it with the target pointcloud (target) using the + operator and assign it to another pointcloud variable (newpointcloud).
newpointcloud = transformed_source + target
o3d.visualization.draw_geometries([newpointcloud])
It gave the same result as the draw_registration_result(source, target, transformation) function when I visualized the pointcloud using o3d.visualization.draw_geometries([newpointcloud]). Even the number of points adds up.
in this scenario i have temp source and temp target like this :
o3d.visualization.draw_geometries([source_temp, target_temp], width=1024, height=768)
should i code like this ?
newpointcloud = source_temp + target_temp o3d.visualization.draw_geometries(newpointcloud) o3d.visualization.write_point_cloud ( "result.ply", [newpointcloud])
After addition, the newpointcloud variable is of type geometry::PointCloud.
- The
draw_geometries()function accepts only a list of geometry::PointCloud variable as the first parameter. So, we should putnewpointcloudwithin[]likeo3d.visualization.draw_geometries([newpointcloud]) - The
write_point_cloud()function belongs to the io class and not to the visualization class. So it should beo3d.io.write_point_cloud()instead ofo3d.visualization.write_point_cloud(). The function accepts only geometry::PointCloud variable as the second parameter. So we don't use a[]. Eg.o3d.io.write_point_cloud("result.ply",newpointcloud)
So overall you are right, except in using the [] brackets.
In my previous comment I missed to include the [] but I edited it now.
Thanks it's working now ... i have another problem. I am trying to combine the two point cloud as .ply files into one file with registration but it's not working fine, can you try to adjust them ... Suggest me where i am doing wrong...?
Code (using Open3D) file and two point cloud file are attached: global_registration.zip
These are two point clouds and need to merge them with any registration method: I am using Global Registration but it's unpredictable, not giving me exact results changed on every Run:
Console window Result:
:: Load two point clouds and disturb initial pose. :: Downsample with a voxel size 0.050. :: Estimate normal with search radius 0.100. :: Compute FPFH feature with search radius 0.250. :: Downsample with a voxel size 0.050. :: Estimate normal with search radius 0.100. :: Compute FPFH feature with search radius 0.250. :: RANSAC registration on downsampled point clouds. Since the downsampling voxel size is 0.050, we use a liberal distance threshold 0.045. registration::RegistrationResult with fitness = 0.396936, inlier_rmse = 0.027044, and correspondence_set size of 285 Access transformation to get result. :: Point-to-plane ICP registration is applied on original point clouds to refine the alignment. This time we use a strict distance threshold 0.020. registration::RegistrationResult with fitness = 0.000000, inlier_rmse = 0.000000, and correspondence_set size of 0 Access transformation to get result.
I have never tried global registration but I did face a similar issue in ICP registration. I will explain what I observed and experienced.
There are two main things to consider:
- The background depth information.
- The transformation between the source and target pointclouds.
The depth points of the background surface (in your case - the wall) in both pointclouds are close to each other. Due to this, the algorithm sees an earlier convergence as it iterates through the points, resulting in the pointcloud that you got. The solution that worked for me was to eliminate these background points. I don't exactly know how to solve this after the pointcloud is obtained. But I did it with my camera's SDK. I used Realsense D435 camera and its SDK's post processing filter (threshold filter) to exclude the points that are beyond a certain distance. This did improve the convergence to a great extent.
Another important thing that I observed was the initial transformation matrix that we give (trans_init). Instead of the matrix you entered (np.asarray([[0.0, 0.0, 1.0, 0.0], [1.0, 0.0, 0.0, 0.0],[0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]])), maybe try estimating the transformation mathematically. If camera 1 is 20 cm away from camera 2 in the positive X direction, the transformation matrix is:
trans_init = np.asarray([[1., 0., 0., 0.20],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
If there is a rotation, you need to find that too and multiply the entire sequence of transformation matrices in reverse order. This article has the formula to find the translation and rotation matrices.
These are my observations and I was able to register the pointclouds properly after taking these 2 considerations. Hope it works for you too.
Ok, im goona read the article, and im using D415 so can you share the code? whatever you did the experiment ... i want to review your code as well.
Eliminating the background is working fine. There is a little offset and I can't figure out or adjust it ... can u suggest what is missing in the parameters?
trans_init = np.asarray( [[0.0, 0.0, 1.0, 0.0], [1.0, 0.0, 0.0, 0.0],[0.1, 1.0, 0.0, 0.0], [0.0, 0.0, 0.1, 1.0]] )
The table should be in a straight line or position. what should I do?
Yep. It was a simple
+operator.Transform the source pointcloud with ICP transformation matrix and save it in one pointcloud variable (
transformed_source), add it with the target pointcloud (target) using the+operator and assign it to another pointcloud variable (newpointcloud).newpointcloud = transformed_source + target o3d.visualization.draw_geometries([newpointcloud])It gave the same result as the
draw_registration_result(source, target, transformation)function when I visualized the pointcloud usingo3d.visualization.draw_geometries([newpointcloud]). Even the number of points adds up.
Dear deepakyeleshetty Thanks so much for your explanation. I have same problem. but I don't know how can I transfer?! Is there any python code for tranformation?
Bests