def test_add_fields(pcd_fname): import pypcd pc = pypcd.PointCloud.from_path(pcd_fname) old_md = pc.get_metadata() # new_dt = [(f, pc.pc_data.dtype[f]) for f in pc.pc_data.dtype.fields] # new_data = [pc.pc_data[n] for n in pc.pc_data.dtype.names] md = {'fields': ['bla', 'bar'], 'count': [1, 1], 'size': [4, 4], 'type': ['F', 'F']} d = np.rec.fromarrays((np.random.random(len(pc.pc_data)), np.random.random(len(pc.pc_data)))) newpc = pypcd.add_fields(pc, md, d) new_md = newpc.get_metadata() # print len(old_md['fields']), len(md['fields']), len(new_md['fields']) # print old_md['fields'], md['fields'], new_md['fields'] assert(len(old_md['fields'])+len(md['fields']) == len(new_md['fields']))
def test_add_fields(pcd_fname): import pypcd pc = pypcd.PointCloud.from_path(pcd_fname) old_md = pc.get_metadata() # new_dt = [(f, pc.pc_data.dtype[f]) for f in pc.pc_data.dtype.fields] # new_data = [pc.pc_data[n] for n in pc.pc_data.dtype.names] md = {'fields': ['bla', 'bar'], 'count': [1, 1], 'size': [4, 4], 'type': ['F', 'F']} d = np.rec.fromarrays((np.random.random(len(pc.pc_data)), np.random.random(len(pc.pc_data)))) newpc = pypcd.add_fields(pc, md, d) new_md = newpc.get_metadata() # print len(old_md['fields']), len(md['fields']), len(new_md['fields']) # print old_md['fields'], md['fields'], new_md['fields'] assert (len(old_md['fields']) + len(md['fields']) == len(new_md['fields']))
def save_result(output_dir, scene_id, points, predictions, ground_truth_labels): output_file_path = os.path.join(output_dir, scene_id + '.pcd') predictions = predictions.astype(np.float32) output_data = np.c_[points, predictions] pcd = pypcd.make_xyz_label_point_cloud(output_data) ground_truth_metadata = { 'fields': ['ground_truth'], 'count': [1], 'size': [4], 'type': ['F'] } ground_truth_dt = np.dtype([('ground_truth', np.float32)]) ground_truth_pc_data = np.rec.fromarrays([ground_truth_labels], dtype=ground_truth_dt) pcd = pypcd.add_fields(pcd, ground_truth_metadata, ground_truth_pc_data) pcd.save_pcd(output_file_path, compression='ascii')