def test_points(): """PyntCloud.points. - Points must be a pandas DataFrame - DataFrame must have at least "x", "y" and "z" named columns - When PyntCloud.points is re-assigned all structures must be removed """ points = np.random.rand(10, 3) # not dataframe with pytest.raises(TypeError): PyntCloud(points) points = pd.DataFrame(points) # not x, y, z with pytest.raises(ValueError): PyntCloud(points) points = pd.DataFrame(points.values, columns=["x", "y", "z"]) assert PyntCloud(points) cloud = PyntCloud(points) cloud.add_structure("voxelgrid") assert len(cloud.structures) == 1 # dummy filter x_above_05 = cloud.points["x"] > 0.5 cloud.points = cloud.points[x_above_05] assert len(cloud.structures) == 0
#Cloud.points is a Pandas Dataframe. #print(cloud.points.columns) # Calculating the best fit plane on the point cloud data and getting the equation of the plane in return _,eq = cloud.add_scalar_field(name = 'plane_fit',max_dist = 5*1e-2) print(eq) a = eq[0] b = eq[1] c = eq[2] d = eq[3] #dis = abs((a * x1 + b * y1 + c * z1 + d)) e = (math.sqrt(a * a + b * b + c * c)) # Making a mask over the points where the inliers of the best fit plane are selected mask = cloud.points['is_plane'] == 1 np.savetxt(r'Plane_inliers.txt',cloud.points[mask], fmt = '%f') #cloud.points[mask] # Removing the inliers from the Point Cloud cloud.points = cloud.points.drop(cloud.points[mask].index) # Calculating the distance of all the points from the Best Fit Plane def distance(x1,y1,z1): return (a * x1 + b * y1 + c * z1 + d) / e cloud.points['distance'] = list(map(distance,cloud.points['x'],cloud.points['y'],cloud.points['z'])) np.savetxt(r'Plane_outliers_behind.txt',cloud.points[cloud.points['distance'] < 0],fmt = '%f')
feature_map_3d = haralick_features_3d(mat, win, dis, theta, levels, props) # Results in different columns of the feature_map. Uncomment to use other features. result = feature_map_3d[:, :, :, 0] #Contrast # result = feature_map_3d[:,:,:,1] #Homogeneity # result = feature_map_3d[:,:,:,2] #ASM # result = feature_map_3d[:,:,:,3] #Energy # result = feature_map_3d[:,:,:,4] #Correlation # Normalizing the result result = ((result - np.min(result)) / (np.max(result) - np.min(result))) * 255 # Mapping the results to the Point Cloud for i in range(len(cloud.points.index)): cloud.points.at[i, 'red'] = result[voxel.voxel_x[i], voxel.voxel_y[i], voxel.voxel_z[i]] cloud.points.at[i, 'green'] = result[voxel.voxel_x[i], voxel.voxel_y[i], voxel.voxel_z[i]] cloud.points.at[i, 'blue'] = result[voxel.voxel_x[i], voxel.voxel_y[i], voxel.voxel_z[i]] cloud.points = cloud.points.drop('grayscale', 1) #cloud.to_file("Contrast_05.txt") np.savetxt(r'Contrast_02.txt', cloud.points.values, fmt='%f') end = time.time() print(end - start)