diff --git a/scripts/visualisation/view_cloud.py b/scripts/visualisation/view_cloud.py deleted file mode 100644 index ac93552..0000000 --- a/scripts/visualisation/view_cloud.py +++ /dev/null @@ -1,178 +0,0 @@ -import argparse -import sys -import os -import open3d as o3d -import numpy as np -from pynput import keyboard -import time -from threading import Thread -from glob import glob -from pathlib import Path - -from wildscenes.tools.utils3d import cidx_2_rgb - - -root_dir = Path(__file__).parent.parent.parent -sys.path.append(str(root_dir)) - - -''' -view_cloud.py - -This script allows for viewing 3D labeled point clouds. Input argument options provided are: ---loaddir - Set to full path to a Wildscenes3d subfolder, e.g. V-01 ---viewpoint - Options: BEV, FPV. Displays the cloud from either a birds eye view or perspective view ---loadidx - Specify which specific cloud to load, or from which cloud to begin viewing a sequence of clouds ---sequential - Default is to load a single cloud then exit. Sequential loads clouds one after another ---video - Plays the clouds sequentially in a continuous video ---videospeed - Defines the video playback speed, lower is faster - -In default and sequential modes, when viewing a cloud, the viewer can be exited by pressing ESC -''' - - -def load_pcd(cloud, labels, fpv=False): - # Load points - pcd = o3d.geometry.PointCloud() - points = np.fromfile(cloud, dtype=np.float32).reshape(-1,3) - # Load colours - labels = np.fromfile(labels, dtype = np.int32) - # Need to remap colours to the output palette - colors = np.array([list(cidx_2_rgb[x]) for x in labels]) / 255 - - if fpv: - index = points[:, 0] >= 0 - points = points[index] - colors = colors[index] - - pcd.points = o3d.utility.Vector3dVector(points) - pcd.colors = o3d.utility.Vector3dVector(colors) - return pcd - - -def create_axis_arrow(size=3.0): - mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=size, origin=[-0, -0, -0]) - return mesh_frame - - -def view_cloud(pcd, coord, view_params, render_param_file, firstloop=True, video=False, videospeed=0.1): - vis.add_geometry(pcd) - vis.add_geometry(coord) - vis.get_render_option().load_from_json(render_param_file) - ctr.convert_from_pinhole_camera_parameters(view_params) - vis.update_geometry(pcd) - vis.update_geometry(coord) - - if not video: - print('Press ESC to exit the submap cloud viz') - - def on_press(key, endkey='esc'): - try: - k = key.char # single-char keys - except: - k = key.name # other keys - - if k == endkey: - print('ending viz ...') - return False # stop listener - - def loop_fun(): - while True: - vis.poll_events() - vis.update_renderer() - time.sleep(0.05) - - listener = keyboard.Listener(on_press=on_press) - listener.start() # start to listen on a separate thread - - # start thread with loop - if firstloop: - t = Thread(target=loop_fun, args=(), name='loop_fun', daemon=True) - t.start() - - listener.join() # wait for endkey - else: - vis.poll_events() - vis.update_renderer() - time.sleep(videospeed) - - vis.remove_geometry(pcd) - vis.remove_geometry(coord) - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--loaddir', default=str(root_dir.parent / 'Wildscenes3d' / 'K-01'), - help="Path to directory in WildScenes to read data, for example K-01") - parser.add_argument('--viewpoint', choices=['BEV', 'FPV'], default='BEV', - help="Choice of viewpoints for rendering the labeled 3D point clouds, either birds eye view or first person view") - parser.add_argument('--loadidx', default=-1, type=int, - help="Specify which cloud index you want to view. Defaults to a random cloud from the traverse") - parser.add_argument('--sequential', default=False, action='store_true', - help="Iteratively view all clouds in a traverse, starting from 0 or loadidx") - parser.add_argument('--video', default=False, action='store_true', - help="View the clouds as a continuous video, starting from 0 or loadidx") - parser.add_argument('--videospeed', default=0.5, type=float, - help='Video playback speed, lower is faster') - args = parser.parse_args() - - cloud_xyz = sorted(glob(os.path.join(args.loaddir, 'Clouds', '*'))) - labels = sorted(glob(os.path.join(args.loaddir, 'Labels', '*'))) - - if args.loadidx >= len(labels): - raise ValueError('Your loadidx is greater than the number of clouds in this traverse') - - if args.viewpoint == 'BEV': - view_params = o3d.io.read_pinhole_camera_parameters( - os.path.join(root_dir, 'wildscenes', 'configs', 'viewpoint_bev.json')) - render_param_file = os.path.join(root_dir, 'wildscenes', 'configs', 'render_bev.json') - else: - view_params = o3d.io.read_pinhole_camera_parameters( - os.path.join(root_dir, 'wildscenes', 'configs', 'viewpoint_fpv.json')) - render_param_file = os.path.join(root_dir, 'wildscenes', 'configs', 'render_fpv.json') - - vis = o3d.visualization.Visualizer() - vis.create_window(width=960, height=1080, visible=True) - ctr = vis.get_view_control() - coord = create_axis_arrow(1) - - if args.sequential: - firstloop = True - if args.loadidx == -1: - args.loadidx = 0 - for idx in range(args.loadidx, len(labels)): - if args.viewpoint == 'BEV': - pcd = load_pcd(cloud_xyz[idx], labels[idx]) - else: - pcd = load_pcd(cloud_xyz[idx], labels[idx], fpv=True) - view_cloud(pcd, coord, view_params, render_param_file, firstloop=firstloop) - firstloop = False - - elif args.video: - if args.loadidx == -1: - args.loadidx = 0 - for idx in range(args.loadidx, len(labels)): - if args.viewpoint == 'BEV': - pcd = load_pcd(cloud_xyz[idx], labels[idx]) - else: - pcd = load_pcd(cloud_xyz[idx], labels[idx], fpv=True) - view_cloud(pcd, coord, view_params, render_param_file, video=True, videospeed=args.videospeed) - - else: - if args.loadidx == -1: - args.loadidx = np.random.randint(len(labels)) - if args.viewpoint == 'BEV': - pcd = load_pcd(cloud_xyz[args.loadidx], labels[args.loadidx]) - else: - pcd = load_pcd(cloud_xyz[args.loadidx], labels[args.loadidx], fpv=True) - - view_cloud(pcd, coord, view_params, render_param_file) - - print('EXITING') \ No newline at end of file diff --git a/scripts/visualisation/view_image.py b/scripts/visualisation/view_image.py deleted file mode 100644 index 90732b9..0000000 --- a/scripts/visualisation/view_image.py +++ /dev/null @@ -1,119 +0,0 @@ -import argparse -import sys -import os -import numpy as np -import cv2 -from glob import glob -from pathlib import Path -from PIL import Image - -from wildscenes.tools.utils2d import METAINFO, class_2_cidx, cidx_2_rgb -from wildscenes.configs.benchmark_palette_remap import custom_label_map - - -root_dir = Path(__file__).parent.parent.parent -sys.path.append(str(root_dir)) - - -''' -view_image.py - -This script allows for viewing 2D labeled images. Input argument options provided are: ---loaddir - Set to full path to a Wildscenes2d subfolder, e.g. V-01 ---loadidx - Specify which specific image to load, or from which image to begin viewing a sequence of images ---sequential - Default is to load a single image then exit. Sequential loads images one after another - press a key to change - the image ---video - Plays the images sequentially in a continuous video ---videospeed - Defines the video playback speed, lower is faster. Setting to zero defaults to sequential mode ---raw - Default is to show the benchmark class set. Raw displays the full class set instead, including rare classes -''' - - -def load_image(imgfile, remap): - img = Image.open(imgfile).convert("P") - base_palette = [254] * 256*3 - for k, v in cidx_2_rgb.items(): - if remap is not None: - v = cidx_2_rgb[remap[k]] # remap to benchmark colors - kk = k*3 - base_palette[kk] = v[0] - base_palette[kk+1] = v[1] - base_palette[kk+2] = v[2] - - img.putpalette(base_palette) - outimg = img.convert("RGB") - - return outimg - - -def view_image(pil_image, sequential=False, videospeed=0): - open_cv_image = np.array(pil_image) - open_cv_image = open_cv_image[:, :, ::-1].copy() - - cv2.imshow('labelled image', open_cv_image) - cv2.waitKey(int(videospeed*1000)) - if not sequential: - cv2.destroyAllWindows() - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--loaddir', default=str(root_dir.parent / 'Wildscenes2d' / 'K-01'), - help="Path to directory in WildScenes to read data, for example K-01") - parser.add_argument('--loadidx', default=-1, type=int, - help="Specify which cloud index you want to view. Defaults to a random cloud from the traverse") - parser.add_argument('--sequential', default=False, action='store_true', - help="Iteratively view all images in a traverse, starting from 0 or loadidx") - parser.add_argument('--video', default=False, action='store_true', - help="View the images as a continuous video, starting from 0 or loadidx") - parser.add_argument('--videospeed', default=0.5, type=float, - help='Video playback speed, lower is faster') - parser.add_argument('--raw', action='store_true', - help="View the raw labels, the full set where pole, asphalt, vehicle and ") - args = parser.parse_args() - - images = sorted(glob(os.path.join(args.loaddir, 'image', '*'))) - labels = sorted(glob(os.path.join(args.loaddir, 'indexLabel', '*'))) # label / indexLabel - - if args.loadidx >= len(labels): - raise ValueError('Your loadidx is greater than the number of images in this traverse') - - if args.raw: - remap = None - else: - remaplist = [] - for classname, color, index in zip(METAINFO['classes'], METAINFO['palette'], METAINFO['cidx']): - print(classname) - remapped_name = custom_label_map[classname] - remapped_index = class_2_cidx[remapped_name] - remaplist.append(remapped_index) - - remap = {i:r for i, r in zip(METAINFO['cidx'], remaplist)} - - if args.sequential: - if args.loadidx == -1: - args.loadidx = 0 - for idx in range(args.loadidx, len(labels)): - labelimg = load_image(labels[idx], remap) - view_image(labelimg, sequential=True) - elif args.video: - if args.loadidx == -1: - args.loadidx = 0 - for idx in range(args.loadidx, len(labels)): - labelimg = load_image(labels[idx], remap) - view_image(labelimg, sequential=True, videospeed=args.videospeed) - else: - if args.loadidx == -1: - args.loadidx = np.random.randint(len(labels)) - labelimg = load_image(labels[args.loadidx], remap) - view_image(labelimg) - - cv2.destroyAllWindows() - print('EXITING') \ No newline at end of file diff --git a/wildscenes/configs/benchmark_palette_remap.py b/wildscenes/configs/benchmark_palette_remap.py deleted file mode 100644 index e6e8eef..0000000 --- a/wildscenes/configs/benchmark_palette_remap.py +++ /dev/null @@ -1,19 +0,0 @@ -custom_label_map = {"unlabelled": "unlabelled", - "asphalt": "other-terrain", - "dirt": "dirt", - "mud": "mud", - "water": "water", - "gravel": "gravel", - "other-terrain": "other-terrain", - "tree-trunk": "tree-trunk", - "tree-foliage": "tree-foliage", - "bush": "bush", - "grass": "grass", - "fence": "fence", - "structure": "structure", - "pole": "other-object", - "vehicle": "unlabelled", - "rock": "rock", - "log": "log", - "other-object": "other-object", - "sky": "sky"} \ No newline at end of file diff --git a/wildscenes/configs/render_bev.json b/wildscenes/configs/render_bev.json deleted file mode 100644 index 3da2b5a..0000000 --- a/wildscenes/configs/render_bev.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "background_color" : [ 1.0, 1.0, 1.0 ], - "class_name" : "RenderOption", - "default_mesh_color" : [ 0.69999999999999996, 0.69999999999999996, 0.69999999999999996 ], - "image_max_depth" : 3000, - "image_stretch_option" : 1, - "interpolation_option" : 0, - "light0_color" : [ 1.0, 1.0, 1.0 ], - "light0_diffuse_power" : 0.66000000000000003, - "light0_position" : [ 0.0, 0.0, 2.0 ], - "light0_specular_power" : 0.20000000000000001, - "light0_specular_shininess" : 100.0, - "light1_color" : [ 1.0, 1.0, 1.0 ], - "light1_diffuse_power" : 0.66000000000000003, - "light1_position" : [ 0.0, 0.0, 2.0 ], - "light1_specular_power" : 0.20000000000000001, - "light1_specular_shininess" : 100.0, - "light2_color" : [ 1.0, 1.0, 1.0 ], - "light2_diffuse_power" : 0.66000000000000003, - "light2_position" : [ 0.0, 0.0, -2.0 ], - "light2_specular_power" : 0.20000000000000001, - "light2_specular_shininess" : 100.0, - "light3_color" : [ 1.0, 1.0, 1.0 ], - "light3_diffuse_power" : 0.66000000000000003, - "light3_position" : [ 0.0, 0.0, -2.0 ], - "light3_specular_power" : 0.20000000000000001, - "light3_specular_shininess" : 100.0, - "light_ambient_color" : [ 0.0, 0.0, 0.0 ], - "light_on" : true, - "line_width" : 1.0, - "mesh_color_option" : 1, - "mesh_shade_option" : 0, - "mesh_show_back_face" : false, - "mesh_show_wireframe" : false, - "point_color_option" : 0, - "point_show_normal" : false, - "point_size" : 3.0, - "show_coordinate_frame" : false, - "version_major" : 1, - "version_minor" : 0 -} \ No newline at end of file diff --git a/wildscenes/configs/render_fpv.json b/wildscenes/configs/render_fpv.json deleted file mode 100644 index 3da2b5a..0000000 --- a/wildscenes/configs/render_fpv.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "background_color" : [ 1.0, 1.0, 1.0 ], - "class_name" : "RenderOption", - "default_mesh_color" : [ 0.69999999999999996, 0.69999999999999996, 0.69999999999999996 ], - "image_max_depth" : 3000, - "image_stretch_option" : 1, - "interpolation_option" : 0, - "light0_color" : [ 1.0, 1.0, 1.0 ], - "light0_diffuse_power" : 0.66000000000000003, - "light0_position" : [ 0.0, 0.0, 2.0 ], - "light0_specular_power" : 0.20000000000000001, - "light0_specular_shininess" : 100.0, - "light1_color" : [ 1.0, 1.0, 1.0 ], - "light1_diffuse_power" : 0.66000000000000003, - "light1_position" : [ 0.0, 0.0, 2.0 ], - "light1_specular_power" : 0.20000000000000001, - "light1_specular_shininess" : 100.0, - "light2_color" : [ 1.0, 1.0, 1.0 ], - "light2_diffuse_power" : 0.66000000000000003, - "light2_position" : [ 0.0, 0.0, -2.0 ], - "light2_specular_power" : 0.20000000000000001, - "light2_specular_shininess" : 100.0, - "light3_color" : [ 1.0, 1.0, 1.0 ], - "light3_diffuse_power" : 0.66000000000000003, - "light3_position" : [ 0.0, 0.0, -2.0 ], - "light3_specular_power" : 0.20000000000000001, - "light3_specular_shininess" : 100.0, - "light_ambient_color" : [ 0.0, 0.0, 0.0 ], - "light_on" : true, - "line_width" : 1.0, - "mesh_color_option" : 1, - "mesh_shade_option" : 0, - "mesh_show_back_face" : false, - "mesh_show_wireframe" : false, - "point_color_option" : 0, - "point_show_normal" : false, - "point_size" : 3.0, - "show_coordinate_frame" : false, - "version_major" : 1, - "version_minor" : 0 -} \ No newline at end of file diff --git a/wildscenes/configs/viewpoint_bev.json b/wildscenes/configs/viewpoint_bev.json deleted file mode 100644 index 54ab96b..0000000 --- a/wildscenes/configs/viewpoint_bev.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "class_name" : "PinholeCameraParameters", - "extrinsic" : - [ - -0.0037207823710047353, - -0.98252480355713379, - 0.1860945087141567, - 0.0, - -0.99655591755247652, - 0.019059495744451947, - 0.080703400257417082, - 0.0, - -0.082839959981214795, - -0.18515330409415579, - -0.97921182336271251, - 0.0, - -0.2680036389056184, - 1.5123774591407972, - 66.300072739451238, - 1.0 - ], - "intrinsic" : - { - "height" : 1080, - "intrinsic_matrix" : - [ - 935.30743608719376, - 0.0, - 0.0, - 0.0, - 935.30743608719376, - 0.0, - 479.5, - 539.5, - 1.0 - ], - "width" : 960 - }, - "version_major" : 1, - "version_minor" : 0 -} \ No newline at end of file diff --git a/wildscenes/configs/viewpoint_fpv.json b/wildscenes/configs/viewpoint_fpv.json deleted file mode 100644 index 7a1b4d7..0000000 --- a/wildscenes/configs/viewpoint_fpv.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "class_name" : "PinholeCameraParameters", - "extrinsic" : - [ - 0.11573866106412747, - 0.0064661638126402611, - 0.99325865264825719, - 0.0, - -0.98848365049883868, - 0.098899054826618399, - 0.11453841997727895, - 0.0, - -0.097491717758859051, - -0.99507646222787804, - 0.017838141396382682, - 0.0, - -0.15640823779809609, - 5.4574940817923068, - 13.083820132382659, - 1.0 - ], - "intrinsic" : - { - "height" : 1080, - "intrinsic_matrix" : - [ - 935.30743608719376, - 0.0, - 0.0, - 0.0, - 935.30743608719376, - 0.0, - 479.5, - 539.5, - 1.0 - ], - "width" : 960 - }, - "version_major" : 1, - "version_minor" : 0 -} \ No newline at end of file diff --git a/wildscenes/tools/utils2d.py b/wildscenes/tools/utils2d.py deleted file mode 100644 index d7b8f18..0000000 --- a/wildscenes/tools/utils2d.py +++ /dev/null @@ -1,86 +0,0 @@ - -METAINFO = { - "classes": ( - "unlabelled", - "asphalt", - "dirt", - "mud", - "water", - "gravel", - "other-terrain", - "tree-trunk", - "tree-foliage", - "bush", - "fence", - "structure", - "pole", - "vehicle", - "rock", - "log", - "other-object", - "sky", - "grass", - ), - "palette": [ - (0, 0, 0), - (230, 25, 75), - (60, 180, 75), - (255, 225, 25), - (0, 130, 200), - (145, 30, 180), - (70, 240, 240), - (240, 50, 230), - (210, 245, 60), - (230, 25, 75), - (0, 128, 128), - (170, 110, 40), - (255, 250, 200), - (128, 0, 0), - (170, 255, 195), - (128, 128, 0), - (250, 190, 190), - (0, 0, 128), - (128, 128, 128), - ], - "cidx": [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18 - ] - } - -def rgb_to_hex(r, g, b): - return '#{:02x}{:02x}{:02x}'. format(int(r), int(g), int(b)) - - -# METAINFO['cidx'] = list(range(len(METAINFO['palette']))) -METAINFO['hex'] = [rgb_to_hex(x[0],x[1],x[2]) for x in METAINFO['palette']] -METAINFO['hash'] = [str(x[0]) + str(x[1]) + str(x[2]) for x in METAINFO['palette']] -hex_2_class = {h:c for h,c in zip(METAINFO['hex'], METAINFO['classes'])} -hex_2_cidx = {h:cidx for h,cidx in zip(METAINFO['hex'], METAINFO['cidx'])} -class_2_hex = {c:h for h,c in hex_2_class.items()} -rgb_2_class = {p:c for p,c in zip(METAINFO['palette'], METAINFO['classes'])} -cidx_2_rgb = {cidx:p for cidx, p in zip(METAINFO['cidx'],METAINFO['palette'])} -cidx_2_class = {cidx:p for cidx, p in zip(METAINFO['cidx'], METAINFO['classes'])} -class_2_cidx = {c:cidx for c, cidx in zip(METAINFO['classes'], METAINFO['cidx'])} - - -hash_2_class = {h:c for h,c in zip(METAINFO['hash'], METAINFO['classes'])} -hash_2_cidx = {h:c for h,c in zip(METAINFO['hash'], METAINFO['cidx'])} -class_2_rgb = {c:p for c,p in zip(METAINFO['classes'], METAINFO['palette'])} \ No newline at end of file diff --git a/wildscenes/tools/utils3d.py b/wildscenes/tools/utils3d.py deleted file mode 100644 index 44d568e..0000000 --- a/wildscenes/tools/utils3d.py +++ /dev/null @@ -1,77 +0,0 @@ - -METAINFO = { - "classes": ( - "unlabelled", - "bush", - "dirt", - "fence", - "grass", - "gravel", - "log", - "mud", - "other-object", - "other-terrain", - "rock", - "sky", - "structure", - "tree-foliage", - "tree-trunk", - "water", - ), - "palette": [ - (0, 0, 0), - (230, 25, 75), - (60, 180, 75), - (0, 128, 128), - (128, 128, 128), - (145, 30, 180), - (128, 128, 0), - (255, 225, 25), - (250, 190, 190), - (70, 240, 240), - (170, 255, 195), - (0, 0, 128), - (170, 110, 40), - (210, 245, 60), - (240, 50, 230), - (0, 130, 200), - ], - "cidx": [ - 255, - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14 - ] - } - -def rgb_to_hex(r, g, b): - return '#{:02x}{:02x}{:02x}'. format(int(r), int(g), int(b)) - - -# METAINFO['cidx'] = list(range(len(METAINFO['palette']))) -METAINFO['hex'] = [rgb_to_hex(x[0],x[1],x[2]) for x in METAINFO['palette']] -METAINFO['hash'] = [str(x[0]) + str(x[1]) + str(x[2]) for x in METAINFO['palette']] -hex_2_class = {h:c for h,c in zip(METAINFO['hex'], METAINFO['classes'])} -hex_2_cidx = {h:cidx for h,cidx in zip(METAINFO['hex'], METAINFO['cidx'])} -class_2_hex = {c:h for h,c in hex_2_class.items()} -rgb_2_class = {p:c for p,c in zip(METAINFO['palette'], METAINFO['classes'])} -cidx_2_rgb = {cidx:p for cidx, p in zip(METAINFO['cidx'],METAINFO['palette'])} -cidx_2_class = {cidx:p for cidx, p in zip(METAINFO['cidx'], METAINFO['classes'])} -class_2_cidx = {c:cidx for c, cidx in zip(METAINFO['classes'], METAINFO['cidx'])} - - -hash_2_class = {h:c for h,c in zip(METAINFO['hash'], METAINFO['classes'])} -hash_2_cidx = {h:c for h,c in zip(METAINFO['hash'], METAINFO['cidx'])} -class_2_rgb = {c:p for c,p in zip(METAINFO['classes'], METAINFO['palette'])} \ No newline at end of file