def range2pcd(Images, path, name, index): cloud_xyz = range2xyz(Images) output_pcd = pypcd.make_xyz_point_cloud(cloud_xyz.reshape(-1, 3)) output_pcd.save( join(path, 'processed pcd', '%s' % name, '%04d.pcd' % index))
def save_point_cloud(pts, filename): pc = pcd.make_xyz_point_cloud(pts) # Write point cloud to file in PCD format metadata = pc.get_metadata() with open(filename, 'w') as fileobj: # Write headers template = "VERSION {version}\nFIELDS {fields}\nSIZE {size}\nTYPE {type}\nCOUNT {count}\nWIDTH {width}\nHEIGHT {height}\nVIEWPOINT {viewpoint}\nPOINTS {points}\nDATA {data}\n" new_fields = [] for f in metadata['fields']: if f == '_': new_fields.append('padding') else: new_fields.append(f) metadata['fields'] = ' '.join(new_fields) metadata['size'] = ' '.join(map(str, metadata['size'])) metadata['type'] = ' '.join(metadata['type']) metadata['count'] = ' '.join(map(str, metadata['count'])) metadata['width'] = str(metadata['width']) metadata['height'] = str(metadata['height']) metadata['viewpoint'] = ' '.join(map(str, metadata['viewpoint'])) metadata['points'] = str(metadata['points']) metadata['data'] = 'ascii' tmpl = template.format(**metadata) fileobj.write(tmpl) pts = pc.pc_data # NOTE Hack to convert structured numpy array to ndarray pts = np.squeeze(pts.view(pts.dtype[0]).reshape(pts.shape + (-1, ))) # Write the data np.savetxt(fileobj, pts, fmt='%.8f')
def writePCD(self, file, cloud): """Write Files PCD. Args: self: The object pointer. file (str): name file. cloud (array): data cloud point. Returns: clouds (str): save cloud points founded. """ X = cloud[:, 0] Y = cloud[:, 1] Z = cloud[:, 2] data = np.column_stack((X, Y, Z)) # Use the pypcd utility function to create a new point cloud from ndarray new_cloud = pypcd.make_xyz_point_cloud(data) # Store the cloud uncompressed fileName = file[:-4] + self.exPCD new_cloud.save_pcd(fileName)
#from sensor_msgs import point_cloud2 #from sensor_msgs.msg import PointCloud2, PointField #from std_msgs.msg import Header from numpy2pcd import get_low_res_input, noise_remove, range2xyz, range2pcd from readpcd import offset_range_img, image_rows_full, image_cols, save_grey_img, create_4dir, progressbar, reverse_offset_range_img range_image_array = np.empty([0, image_rows_full, image_cols, 1], dtype=np.float32) file_path = '/home/yifu/data/long_experiment/cloud_0000_1583840211_539847424.pcd' pc = pypcd.PointCloud.from_path(file_path) pcdata = pc.pc_data.view(np.float32).reshape(-1, 3) np.savetxt("/home/yifu/data/long_experiment/processed pcd/raw %s.csv" % sys.version[:3], pcdata, delimiter=",") range_image = offset_range_img(pcdata) # recover cloud = range2xyz(range_image[0]) cloud = reverse_offset_range_img(cloud) np.savetxt("/home/yifu/data/long_experiment/processed pcd/%s.csv" % sys.version[:3], cloud, delimiter=",") output_pcd = pypcd.make_xyz_point_cloud(cloud.reshape(-1, 3)) output_pcd.save( join('/home/yifu/data/long_experiment/processed pcd/numpysave.pcd'))