def test_radius_outlier_removal_alias(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output1 = pclpy.radius_outlier_removal(pc, search_radius=0.5, min_neighbors=10) output2 = pclpy.ror(pc, search_radius=0.5, min_neighbors=10) assert np.allclose(output1.xyz, output2.xyz)
def test_greedy_projection_triangulation_simple(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") cloud_with_normals = pcl.PointCloud.PointNormal() pc.compute_normals(radius=0.15, output_cloud=cloud_with_normals, num_threads=8) ms = pcl.surface.GreedyProjectionTriangulation.PointNormal() pi = 3.141592 triangles = pcl.PolygonMesh() ms.setSearchRadius(0.2) ms.setMu(2.5) ms.setMaximumNearestNeighbors(100) ms.setMaximumSurfaceAngle(pi / 4) ms.setMinimumAngle(pi / 18) ms.setMaximumAngle(2 * pi / 3) ms.setNormalConsistency(True) ms.setInputCloud(cloud_with_normals) tree2 = pcl.search.KdTree.PointNormal() ms.setSearchMethod(tree2) ms.reconstruct(triangles) assert 125 < len(triangles.polygons ) < 250 # depending on the build, this number can vary...
def test_moving_least_squares_alias(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output1 = pclpy.moving_least_squares(pc, search_radius=0.5, compute_normals=False) output2 = pclpy.mls(pc, search_radius=0.5, compute_normals=False) assert np.allclose(output1.xyz, output2.xyz)
def test_moving_least_squares_no_normals(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output = pclpy.moving_least_squares(pc, search_radius=0.5, compute_normals=False) assert output.size() == 4942 assert not hasattr(output, "normals")
def test_radius_outlier_removal_negative(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output = pclpy.radius_outlier_removal(pc, search_radius=0.5, min_neighbors=10, negative=True) assert output.size() == 721
def test_difference_of_normals_estimation_simple(): pc = pclpy.read(test_data("street.las"), "PointXYZRGBA") pc_subsampled = pclpy.octree_voxel_downsample(pc, 0.05) subsampled = pclpy.octree_voxel_downsample(pc_subsampled, 0.4) normals_large = pcl.PointCloud.PointNormal() pc_subsampled.compute_normals(radius=4, output_cloud=normals_large, num_threads=8, search_surface=subsampled) normals_small = pcl.PointCloud.PointNormal() pc_subsampled.compute_normals(radius=0.10, output_cloud=normals_small, num_threads=8) don = pcl.features.DifferenceOfNormalsEstimation.PointXYZRGBA_PointNormal_PointNormal( ) don.setInputCloud(pc_subsampled) don.setNormalScaleLarge(normals_large) don.setNormalScaleSmall(normals_small) output = pcl.PointCloud.PointNormal(pc_subsampled.xyz) don.computeFeature(output) indices = np.argwhere(output.curvature > 0.4) output2 = pcl.PointCloud.PointNormal(output, pcl.vectors.Int(indices)) clusters = pclpy.extract_clusters(pcl.PointCloud.PointXYZ(output2.xyz), 0.1, 50, 100000) assert len(clusters) == 32
def test_las_read_normals(): pc = pclpy.read(test_data("street_thinned_with_normals.las"), "PointNormal") assert hasattr(pc, "normal_x") assert hasattr(pc, "normal_y") assert hasattr(pc, "normal_z") assert hasattr(pc, "curvature")
def test_radius_outlier_removal_indices(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") indices = pcl.vectors.Int(np.arange(10, 1000, dtype="i")) output = pclpy.radius_outlier_removal(pc, search_radius=0.5, min_neighbors=10, indices=indices) assert output.size() == 889
def test_las_to_pcd(temp_file): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") writer = pcl.io.PCDWriter() writer.writeBinary(temp_file, pc) reader = pcl.io.PCDReader() pcd = pcl.PointCloud.PointXYZ() reader.read(temp_file, pcd) assert pcd.size() == 5025
def test_voxel_centroid_simple(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") vox = pcl.octree.OctreePointCloudVoxelCentroid.PointXYZ(0.3) vox.setInputCloud(pc) vox.addPointsFromInputCloud() centroids = pcl.PointCloud.PointXYZ() vox.getVoxelCentroids(centroids.points) assert centroids.size() == 3148
def test_extract_indices_simple(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") extract = pcl.filters.ExtractIndices.PointXYZ() extract.setInputCloud(pc) pi = pcl.PointIndices() pi.indices.append(3) extract.setIndices(pi) out = pcl.PointCloud.PointXYZ() extract.filter(out) assert np.allclose(out.xyz, np.array([[12.259, -0.124, 21.9086]], "f"))
def test_las_write_with_offset(temp_las_path): a = np.random.ranf(3).reshape(-1, 3) pc = pcl.PointCloud.PointXYZ.from_array(a) pclpy.write_las(pc, temp_las_path, xyz_offset=[10, 10, 10]) pc = pclpy.read(temp_las_path, "PointXYZ") assert np.all(pc.x >= 10) assert np.all(pc.x <= 11) assert np.all(pc.y >= 10) assert np.all(pc.y <= 11) assert np.all(pc.z >= 10) assert np.all(pc.z <= 11)
def test_compute_normals_simple_given_output(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") pc.compute_normals(radius=1) pc2 = pcl.PointCloud.PointNormal(pc.xyz) assert np.allclose(pc.xyz, pc2.xyz) output = pclpy.compute_normals(pc2, radius=1, output_cloud=pc2) normals = output.normals nan = np.sum(np.isnan(normals), axis=1) assert np.sum(nan) != normals.shape[0] assert np.sum(nan) == 6 norm = np.linalg.norm(normals[~nan], axis=1) assert np.allclose(norm, 1., atol=0.001)
def test_supervoxel_clustering(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") normals = pc.compute_normals(radius=0.3) vox = pcl.segmentation.SupervoxelClustering.PointXYZRGBA(voxel_resolution=1, seed_resolution=2) vox.setInputCloud(pc) vox.setNormalCloud(normals) # vox.setSpatialImportance(2) # vox.setNormalImportance(2) # vox.setColorImportance(2) output = pcl.vectors.map_uint32t_PointXYZRGBA() vox.extract(output) assert len(list(output.items())) == 91
def test_las_read_with_offset(temp_las_path): a = np.random.ranf(3).reshape(-1, 3) pc = pcl.PointCloud.PointXYZ.from_array(a) offset = [10, 10, 10] pclpy.write_las(pc, temp_las_path, xyz_offset=offset) file_offset = pclpy.io.las.get_offset(temp_las_path) assert np.allclose(offset, file_offset) pc = pclpy.read(temp_las_path, "PointXYZ", xyz_offset=offset) assert np.all(pc.x >= 0) assert np.all(pc.x <= 1) assert np.all(pc.y >= 0) assert np.all(pc.y <= 1) assert np.all(pc.z >= 0) assert np.all(pc.z <= 1)
def test_region_growing_simple(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") normals = pc.compute_normals(radius=0.35) clusters = pclpy.region_growing(pc, normals=normals, min_size=10, max_size=1000000, n_neighbours=15, smooth_threshold=5, curvature_threshold=5, residual_threshold=1, ) assert max([len(c.indices) for c in clusters]) == 2449 # ground
def test_region_growing(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") rg = pcl.segmentation.RegionGrowing.PointXYZRGBA_Normal() rg.setInputCloud(pc) normals_estimation = pcl.features.NormalEstimationOMP.PointXYZRGBA_Normal() normals_estimation.setInputCloud(pc) normals = pcl.PointCloud.Normal() normals_estimation.setRadiusSearch(0.35) normals_estimation.compute(normals) rg.setInputNormals(normals) rg.setMaxClusterSize(1000000) rg.setMinClusterSize(10) rg.setNumberOfNeighbours(15) rg.setSmoothnessThreshold(5 / 180 * math.pi) rg.setCurvatureThreshold(5) rg.setResidualThreshold(1) clusters = pcl.vectors.PointIndices() rg.extract(clusters) assert max([len(c.indices) for c in clusters]) == 2449 # ground
def test_fpfh_simple(): pc = pclpy.read(test_data("street.las"), "PointXYZ") pc = pclpy.octree_voxel_downsample(pc, 0.25) normals = pc.compute_normals(radius=0.5, num_threads=8) fpfh = pcl.features.FPFHEstimation.PointXYZ_Normal_FPFHSignature33() fpfh.setInputCloud(pc) fpfh.setInputNormals(normals) fpfh.setRadiusSearch(0.5) fpfhs = pcl.PointCloud.FPFHSignature33() fpfh.compute(fpfhs) expected_bottom_right = np.array([ [6.2739134, 2.528063, 2.078603], [1.3269598, 1.0290794, 0.27428713], [0., 0., 0.], ]) assert np.allclose(fpfhs.histogram[-3:, -3:], expected_bottom_right)
def test_euclidean_cluster(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") # type: pcl.PointCloud.PointXYZRGBA indices = pc.extract_clusters(tolerance=0.5, min_size=10, max_size=100000) assert len(indices[0].indices) == 4799
def test_voxel_centroid_api(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output = pclpy.octree_voxel_centroid(pc, resolution=0.3) assert output.size() == 3148
def test_las_intensity(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZI") assert pc.size() == 5025 assert np.any(pc.intensity)
def test_las_rgb(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") assert pc.size() == 5025 assert np.any(pc.r)
def test_las_xyz(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") assert pc.size() == 5025
#%% import pclpy from pclpy import pcl #%% point_cloud = pclpy.read( r"C:\Users\laptop\Google Drive\Google Drive\Shared folder Tasos-VanBoven\Sample_data\Broccoli\35m\Rijweg_stalling1-8-5.las", "PointXYZRGBA") mls = pcl.surface.MovingLeastSquaresOMP.PointXYZRGBA_PointNormal() tree = pcl.search.KdTree.PointXYZRGBA() mls.setSearchRadius(0.05) mls.setPolynomialFit(False) mls.setNumberOfThreads(12) mls.setInputCloud(point_cloud) mls.setSearchMethod(tree) mls.setComputeNormals(True) output = pcl.PointCloud.PointNormal() mls.process(output) # ============================================================================= # visual = pclpy.show(tree) # visual.ShowColorACloud(cloud, b'cloud') # =============================================================================
def test_viewer_intensity(): pc = pclpy.read(test_data("street.las"), "PointXYZI") viewer = pclpy.Viewer(pc)
def test_moving_least_squares_with_output(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output = pcl.PointCloud.PointNormal() pclpy.moving_least_squares(pc, search_radius=0.5, output_cloud=output) assert output.size() == 4942
def test_compute_normals_simple(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZ") output = pclpy.compute_normals(pc, radius=1) assert np.any(output.normals)
def pre_process_pc(self): if os.path.exists( unlabelled_configure.get("Constants", "pkl_file_path")): return # read a las file point_cloud = pclpy.read( unlabelled_configure.get("Test", "las_file_path"), "PointXYZ") output = unlabelled_configure.get("Test", "pcd_output_path") writer = pcl.io.PCDWriter() writer.writeBinary(output, point_cloud) # pcd = o3d.io.read_point_cloud("../lidar/data/4810E_54560N.pcd") pcd = o3d.io.read_point_cloud(output) input_data = np.asarray(pcd.points) input_data[:, 0] = input_data[:, 0] - 481000 input_data[:, 1] = input_data[:, 1] - 5456000 pcd.points = o3d.utility.Vector3dVector(input_data) UTM_10_PROJ = Proj( "+proj=utm +zone=10N, +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs" ) filename = unlabelled_configure.get("Test", "dem_path") xyz = open(filename, "r") count = 0 for line in xyz: count += 1 xyz.close() xyz = open(filename, "r") dem_points = np.ndarray((count, 3)) count = 0 for line in xyz: x, y, z = line.split() # lat, lon = UTM_10_PROJ(x, y, inverse=True) dem_points[count, :] = np.array([x, y, z]) count += 1 xyz.close() dem_points[:, 0] = dem_points[:, 0] - 481000 dem_points[:, 1] = dem_points[:, 1] - 5456000 dem_pcd = o3d.geometry.PointCloud() dem_pcd.points = o3d.utility.Vector3dVector(dem_points) downpcd = pcd.uniform_down_sample( every_k_points=self.uniform_down_k_point) dists = downpcd.compute_point_cloud_distance(dem_pcd) dists = np.asarray(dists) downpcd_points = np.asarray(downpcd.points) downpcd_points[:, 2] = dists downpcd.points = o3d.utility.Vector3dVector(downpcd_points) plane_model, inliers = downpcd.segment_plane( distance_threshold=self.distance_threshold, ransac_n=self.ransac_n, num_iterations=self.num_iterations) inlier_cloud = downpcd.select_by_index(inliers) ground_diff = downpcd.compute_point_cloud_distance(inlier_cloud) ground_diff = np.asarray(ground_diff) ind = np.where(ground_diff > self.ground_threshold)[0] pcd_without_ground = downpcd.select_by_index(ind) with open(unlabelled_configure.get("Constants", "pkl_file_path"), "wb") as f: pickle.dump(np.asarray(pcd_without_ground.points), f) print(np.asarray(pcd_without_ground.points).shape)
def test_voxel_centroid_api_rgba(): pc = pclpy.read(test_data("street_thinned.las"), "PointXYZRGBA") output = pclpy.octree_voxel_downsample(pc, resolution=0.3, centroids=False) assert output.size() == 3148