def ply2pcd(file_path=None): if file_path is None: file_path, file_format = get_file() cloud = pcl.load(file_path, cloud_format) file_path = file_path[:-3] print(file_path) pcl.save_XYZRGBA(cloud, (file_path + "pcd"), format="pcd")
def demo_crop_geometry(): print("Demo for manual geometry cropping") print( "1) Press 'Y' twice to align geometry with negative direction of y-axis" ) print("2) Press 'K' to lock screen and to switch to selection mode") print("3) Drag for rectangle selection,") print(" or use ctrl + left click for polygon selection") print("4) Press 'C' to get a selected geometry and to save it") print("5) Press 'F' to switch to freeview mode") source_path, source_format = get_file() pcd = o3d.io.read_point_cloud(source_path) o3d.visualization.draw_geometries_with_editing([pcd])
information_icp, uncertain=False)) else: # loop closure case pose_graph.edges.append( o3d.registration.PoseGraphEdge(source_id, target_id, transformation_icp, information_icp, uncertain=True)) return pose_graph if __name__ == "__main__": o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug) pcd_p, pcd_f = get_file() pcds_down = load_point_clouds(voxel_size) o3d.visualization.draw_geometries(pcds_down) print("Full registration ...") pose_graph = full_registration(pcds_down, max_correspondence_distance_coarse, max_correspondence_distance_fine) print("Optimizing PoseGraph ...") option = o3d.registration.GlobalOptimizationOption( max_correspondence_distance=max_correspondence_distance_fine, edge_prune_threshold=0.25, reference_node=0) o3d.registration.global_optimization( pose_graph, o3d.registration.GlobalOptimizationLevenbergMarquardt(),
viewer.SpinOnce() print("") print("Done.") while view: viewer.Spin() view = not (viewer.WasStopped()) return accumulate_clouds if __name__ == "__main__": while (True): cloud_path, cloud_format = get_file() # for path in cloud_path: folder_name = cloud_path[-13:-4] cluster_index = 0 cluster_name = str(cluster_index)[-4:] print("Cluster_" + str(cluster_index)[-4:] + "." + cloud_format) pcl_cloud = pcl.load(cloud_path, cloud_format) # for i in range(400): clusters = segment(pcl_cloud, 2.75, min_cluster=5, view=False) for cluster in clusters: # pcl.save(cluster, ("./data/PRICT-28/clusters/Cluster_" + str(cluster_index)[-4:] + "." + cloud_format), # format=cloud_format)
[0, 1], [0, 2], [0, 3], ] #each vector is red, green blue are PCA1, PCA2 and PCA3 respectivley. colors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] #create open3d linesets. line_set = o3d.LineSet() line_set.points = o3d.Vector3dVector(points) line_set.lines = o3d.Vector2iVector(lines) line_set.colors = o3d.Vector3dVector(colors) return line_set if __name__ == "__main__": cloud_path, cloud_format = load.get_file() # cloud = pcl.load(cloud_path,cloud_format) cloud = o3d.io.read_point_cloud(cloud_path, format="ply") #Perform PCA on entire object vectors, center, result = get_pca(cloud) #create vectors in o3d linesets line_set = o3d_pca_geometry(vectors, center) #display in o3d o3d.draw_geometries([cloud, line_set])
ax.plot(zAxisLine[0], zAxisLine[1], zAxisLine[2], 'r') # label the axes ax.set_xlabel("X") ax.set_ylabel("Y") ax.set_zlabel("Z") ax.set_title("") # plt.show(block=True) return (xAxisLine[0],yAxisLine[1],zAxisLine[2]) if __name__ == "__main__": source_dir, f1 = load.get_file() target_dir, f2 = load.get_file() print(source_dir) o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug) source_raw = o3d.io.read_point_cloud(source_dir, format = f1) target_raw = o3d.io.read_point_cloud(target_dir, format = f2) # source = o3d.geometry.voxel_down_sample(source_raw, voxel_size=0.02) # target = o3d.geometry.voxel_down_sample(target_raw ,voxel_size=0.02) source, source_fpfh = preprocess_point_cloud(source_raw, voxel_size=0.1) target, target_fpfh = preprocess_point_cloud(target_raw, voxel_size=0.1) result = execute_global_registration(source, target, source_fpfh, target_fpfh, voxel_size=0.1)
def draw_registration_result(source, target, transformation): source_temp = copy.deepcopy(source) target_temp = copy.deepcopy(target) source_temp.paint_uniform_color([1, 0.706, 0]) target_temp.paint_uniform_color([0, 0.651, 0.929]) source_temp.transform(transformation) o3d.visualization.draw_geometries([source_temp, target_temp]) if __name__ == "__main__": # main() source_path, source_format = get_file() target_path, target_format = get_file() source = o3d.io.read_point_cloud(source_path) target = o3d.io.read_point_cloud(target_path) threshold = 0.02 trans_init = np.asarray([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1 , 0], [0.0, 0.0, 0.0, 1.0]]) print("Initial alignment") evaluation = o3d.registration.evaluate_registration(source, target, threshold, trans_init) print(evaluation) print("Apply point-to-point ICP") reg_p2p = o3d.registration.registration_icp(