def test(): from svstools import visualization as vis train_set = S3DISDataset("/home/burak/workspace/seg/data", split=SPLITS[1]['train']) data, labels = train_set[213] pc = data[:3].T pcd = vis.paint_colormap(pc, labels) vis.show_pointcloud(pcd, coordinate_frame=[1, [0, 0, 0]]) return
def test2(): np.random.seed(0) import sys sys.path.append("/seg") from datasets.s3dis.dataset import Dataset dataset = Dataset(split='test', crossval_id=1, num_points=2**17) data, labels, groups = dataset[5] length = 128 for h in [5, 3]: sub_pc, grouping, bboxes = groups[h] groups_array = [] masks = [] group_features = np.zeros((6, len(grouping), length), dtype=data.dtype) for i, g in enumerate(grouping): num_dummy = length - len(g) # m = np.append(np.ones(len(g), dtype=np.bool), np.zeros(num_dummy, dtype=np.bool)) g = np.append(g, np.repeat(g[0], num_dummy)) group_features[:, i] = data[:, g] # groups_array.append(g) # masks.append(m) # groups_array = np.asarray(groups_array) # masks = np.asarray(masks) # for continue sub_pc, grouping, bboxes = groups[3] neighborhood = get_neighborhood(sub_pc.T, k=8) neighborhood_mesh = draw_neighborhood2(sub_pc[:3].T, neighborhood) spheres = o3d.geometry.TriangleMesh() boxes = o3d.geometry.LineSet() for p, bb in zip(sub_pc.T, bboxes): spheres += vis.draw_sphere(p[:3], 0.001) boxes += vis.draw_bbox(bb, color=[0, 0, 1]) vis.show_pointcloud(data.T, [spheres, boxes, neighborhood_mesh]) return
def make_object_grid(objects, grid): assert np.prod(grid) == len(objects) # coords = np.array(np.meshgrid(np.arange(grid[0]), np.arange(grid[1]))) # coords = coords.transpose(0, 2, 1).reshape(-1,2) # coords = np.hstack((coords, np.zeros((len(coords), 1)))).astype(float) coords = [] for x in range(grid[0]): for y in range(grid[1]): coords += [[x, y, 0.0]] coords = np.array(coords) * 3.0 geometries = [] for obj, coord in zip(objects, coords): geometries += [obj.translate(coord)] vis.show_pointcloud([], geometries) return
def get_modelnet_grid(): from utils.datasets import modelnet sets = modelnet.get_sets("data/modelnet") train_set = sets[0] labels = train_set.label.reshape(-1) objects = [] for c in [7]: print(modelnet40_objects[c]) i = np.where(labels == c)[0][2] pc = train_set.data[i] pcd = pc_utils.points2PointCloud(pc) vis.show_pointcloud(pcd) pcd = pcd.rotate([0,30,0]) objects += [pcd] make_object_grid(objects, [5, 8])
def draw_boxes(pc, coordinates, box_size=0.2, point_limit=2**15): c = coordinates[..., np.newaxis] bboxes = np.concatenate((c, c + box_size), axis=-1).reshape(-1, 6) sub_pc = c.reshape(-1, 3) + box_size / 2 neighborhood = get_neighborhood(sub_pc, k=8) neighborhood_mesh = draw_neighborhood(sub_pc, neighborhood) spheres = o3d.geometry.TriangleMesh() boxes = o3d.geometry.LineSet() for p, bb in zip(sub_pc, bboxes): spheres += vis.draw_sphere(p[:3], 0.001) boxes += vis.draw_bbox(bb, color=[0, 0, 1]) if point_limit > 0: pc = pc[np.random.permutation(len(pc))[:point_limit]] vis.show_pointcloud(pc, [spheres, boxes, neighborhood_mesh])
def test(): from svstools import visualization as vis print("loading dataset") dataloader = ScanNetDataset('data/scannet', split='train') scene = dataloader.loaded["test/captures/scene0707_00.npy"] num_points = 2**17 # Get target indices indices = np.arange(len(scene)) if len(scene) < num_points: indices = np.append( indices, np.random.permutation(len(scene))[:len(scene) - num_points]) np.random.shuffle(indices) scene = scene[indices, :6] vis.show_pointcloud(scene)
def draw_room(cloud, labels=None, mode="point"): # indices = np.random.permutation(len(cloud))[:2**15] # cloud = cloud[indices] # labels = labels[indices] color_map = [vis.get_color(i, N=13) for i in range(len(categories))] if labels is not None: colors = np.asarray([color_map[l] for l in labels]) elif cloud.shape[1] == 6: colors = cloud[:, 3:6] else: raise ValueError("No color information provided!") if mode == "sphere": spheres = vis.o3d.geometry.TriangleMesh() for p, c in zip(cloud, colors): spheres += vis.draw_sphere(p, radius=0.01, color=c) vis.show_pointcloud(np.array([[0, 0, 0]]), geometries=[spheres]) elif mode == "point": painted = np.column_stack((cloud, colors)) vis.show_pointcloud(painted)
def test(): from svstools import visualization as vis # loaded = np.loadtxt("/home/burak/datasets/Stanford3d_batch_version/Area_1/office_1/Batch_Folder/batch_10.txt") # pc, labels = loaded[:, :3], loaded[:, -1].astype(np.int32) loaded = np.load("augmentations_test.npz") pc, labels = loaded["pc"], loaded["labels"] labels += 1 pcd_colored_org = vis.pc_utils.points2PointCloud( vis.paint_colormap(pc, labels)) cf_org = vis.o3d.geometry.TriangleMesh.create_coordinate_frame( size=0.5, origin=[0, 0, 0]) target_augmentations = [ ["rotate_point_cloud", rotate_point_cloud, ()], ["shift_point_cloud", shift_point_cloud, ()], ["jitter_point_cloud", jitter_point_cloud, ()], ["random_scale_point_cloud", random_scale_point_cloud, ()], ] shift = 4 batch = pc[np.newaxis, ...] for name, aug, args in target_augmentations: print("Augmentation: %s" % (name)) pc = aug(batch.copy(), *args)[0] pc[:, 0] += shift pcd_colored = vis.pc_utils.points2PointCloud( vis.paint_colormap(pc, labels)) cf = vis.o3d.geometry.TriangleMesh.create_coordinate_frame( size=0.5, origin=[shift, 0, 0]) geometries = [cf, cf_org, pcd_colored_org] vis.show_pointcloud(pcd_colored, geometries=geometries)
def main(): file_path = "/seg/scripts/output.npz" npz = np.load(file_path, allow_pickle=True) cloud = npz["cloud"] preds = npz["preds"] labels = npz["labels"] # d = dataset.Dataset(split="test", crossval_id=1) # cloud, gt, meta = d[0] pc = cloud[0].T p, l = preds.argmax(axis=-2)[0], labels[0] pc = vis.paint_colormap(pc, p) # pc = pc_utils.pointCloud2Points(pcd) bbox = np.row_stack( (pc[:, :3].min(axis=0), pc[:, :3].max(axis=0))).T.reshape(-1) bbox[-1] -= 0.05 # pc = pc[pc_utils.crop_bbox(pc, bbox)] vis.show_pointcloud(pc, coordinate_frame=(0.01, (0, 0, 0)))