def main(): trajectories = sn.Trajectories() parser = argparse.ArgumentParser() parser.add_argument("protobuf_path", type=str, help="path of the protobuf file") parser.add_argument("data_path", type=str, help="path of the data") parser.add_argument("--vis_points", default=False, action="store_true", help="path of the data") parser.add_argument("--skip_exists", default=True, action="store_false", help="skip existing files") args = parser.parse_args() protobuf_path = args.protobuf_path data_path = args.data_path try: with open(protobuf_path, 'rb') as f: trajectories.ParseFromString(f.read()) except IOError: print('Scenenet protobuf data not found at location:{0}'.format( data_root_path)) print( 'Please ensure you have copied the pb file to the data directory') pass unproj(trajectories, args) # start = time.time() # has_overlap_view(trajectories.trajectories[0], args) # end = time.time() # print("overlap time: {}".format(end - start)) pass
def __init__(self): super(Dataset_).__init__() self.trajectories = sn.Trajectories() with open(Util.protobuf_path, 'rb') as f: self.trajectories.ParseFromString(f.read()) self.cached_pixel_to_ray_array = Util.normalised_pixel_to_ray_array() self.instance_class_map = {}
def main(protobuf_path, shapenet_dir, layout_dir, indices): trajectories_pb = sn.Trajectories() try: with open(protobuf_path, 'rb') as f: trajectories_pb.ParseFromString(f.read()) except IOError: print('Scenenet protobuf data not found at location:{0}'.format(protobuf_path)) raise trajectories = trajectories_pb.trajectories if indices: trajectories = [trajectories[i] for i in indices] for i, traj in enumerate(trajectories): convert_trajectory(i, traj, shapenet_dir, layout_dir) print('Scene Generation Complete')
def CalculateSurfaceNormalsApp(): parser = argparse.ArgumentParser(description='Normals generator application.') parser.add_argument('--data-root-path', type=str, required=True, help='the path to the dataset root.') parser.add_argument('--protobuf-path', type=str, required=True, help='the path to the protobuf to extract the data.') parser.add_argument('--num-steps', type=int, default=30, help='the number samples to skip.') parser.add_argument('--num-workers', type=int, default=4, help='the number of workers to use to compute the normals.') args = parser.parse_args() trajectories = sn.Trajectories() try: with open(args.protobuf_path,'rb') as f: trajectories.ParseFromString(f.read()) except IOError: print('Scenenet protobuf data not found at location:{0}'.format(data_root_path)) print('Please ensure you have copied the pb file to the data directory') global_idx = 0 paths = [] for traj_idx, traj in enumerate(trajectories.trajectories): for view_idx, view in enumerate(traj.views): if global_idx % args.num_steps != 0: global_idx += 1 continue global_idx += 1 # prepare data paths depth_path = depth_path_from_view( args.data_root_path, traj.render_path, view) surface_normal_path = normals_path_from_view( args.data_root_path, traj.render_path, view) paths.append((depth_path, surface_normal_path)) p = mp.Pool(processes=args.num_workers) p.map(calculate_normals, paths)
pose.timestamp = timestamp return pose data_root_path = 'data/val' protobuf_path = 'data/scenenet_rgbd_val.pb' def photo_path_from_view(render_path, view): photo_path = os.path.join(render_path, 'photo') image_path = os.path.join(photo_path, '{0}.jpg'.format(view.frame_num)) return os.path.join(data_root_path, image_path) if __name__ == '__main__': trajectories = sn.Trajectories() try: with open(protobuf_path, 'rb') as f: trajectories.ParseFromString(f.read()) except IOError: print('Scenenet protobuf data not found at location:{0}'.format( data_root_path)) print( 'Please ensure you have copied the pb file to the data directory') for idx, a_traj in enumerate(trajectories.trajectories): if a_traj.render_path == '0/68': traj = a_traj break # This is the 3D position of the center of the spherical light in # the validation trajectory '0/68' in world coordinates
def main(): """Generate light specs and obj file name""" parser = argparse.ArgumentParser( usage= "python generate_scene_desc.py --pb=<path> --tmpl=<scene-template>") parser.add_argument('--tmpl', type=str, help='Scene template json file.') parser.add_argument('--pb', type=str, help='Path to the protobuf file.') parser.add_argument('--out', type=str, required=True, help='Output directory') parser.add_argument('--data-root', type=str, default='./', help='Data root.') args = parser.parse_args() print(args) protobuf_path = os.path.expanduser(args.pb) data_root_path = os.path.expanduser(args.data_root) out_dir = os.path.expanduser(args.out) if not os.path.exists(out_dir): os.makedirs(out_dir) trajectories = sn.Trajectories() try: with open(protobuf_path, 'rb') as f: trajectories.ParseFromString(f.read()) except IOError: print('Scenenet protobuf data not found at location:{0}'.format( data_root_path)) print('Number of trajectories:{0}'.format(len(trajectories.trajectories))) for traj_no, traj in enumerate(trajectories.trajectories): layout_type = sn.SceneLayout.LayoutType.Name(traj.layout.layout_type) layout_path = traj.layout.model print('=' * 20) print('Render path:{0}'.format(traj.render_path)) print('Layout type:{0} path:{1}'.format(layout_type, layout_path)) print('=' * 20) obj_filename = 'trajectory_{}.obj'.format(traj_no) print(obj_filename) scene_desc = { "file-format": { "type": "diffrend", "version": "0.2" }, "glsl": { "vertex": "../shaders/phong/vs.glsl", "fragment": "../shaders/phong/fs.glsl" }, "camera": { "proj_type": "perspective", "viewport": [0, 0, 640, 480], "fovy": 1.04, "focal_length": 1.0, "eye": [3.5, 2.0, 3.5, 1.0], "up": [0.0, 1.0, 0.0, 0.0], "at": [0.0, 1.0, 0.0, 1.0], "near": 0.1, "far": 1000.0 }, "lights": { "pos": [], "color_idx": [], "attenuation": [], "ambient": [0.01, 0.01, 0.01] }, "colors": [], "materials": { "albedo": [[0.0, 0.0, 0.0], [0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.5, 0.5, 0.5], [0.8, 0.8, 0.8], [0.44, 0.55, 0.64]], "coeffs": [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]] }, "objects": { "obj": [{ "path": "../objs/scenenetrgbd/" + obj_filename, "material_idx": 4, "scale": [1.0, 1.0, 1.0] }] }, "tonemap": { "type": "gamma", "gamma": [1.0] } } for instance in traj.instances: if instance.instance_type == sn.Instance.LIGHT_OBJECT: light = instance.light_info light_type = sn.LightInfo.LightType.Name(light.light_type) light_intensity = [ light.light_output.r, light.light_output.g, light.light_output.b ] light_pos = [ light.position.x, light.position.y, light.position.z ] print('=' * 20) print('Light type:{0}'.format(light_type)) print(light) print('emission: ', light_intensity) print('pos: ', light_pos) scene_desc["colors"].append(light_intensity) scene_desc['lights']["color_idx"].append( len(scene_desc["colors"]) - 1) scene_desc['lights']["pos"].append(light_pos) scene_desc['lights']["attenuation"].append([0.0, 0.0, 0.4]) print(scene_desc) outfilename = 'scenenet_{:04}.json'.format(traj_no) print(outfilename) with open(os.path.join(out_dir, outfilename), 'w') as fid: json.dump(scene_desc, fid)
def main(): parser = argparse.ArgumentParser(usage="read_protobuf") parser.add_argument('--pb', type=str, help='Path to the protobuf file.') parser.add_argument('--out', type=str, required=True, help='Output directory') parser.add_argument('--data-root', type=str, default='./', help='Data root.') args = parser.parse_args() print(args) protobuf_path = os.path.expanduser(args.pb) data_root_path = os.path.expanduser(args.data_root) out_dir = os.path.expanduser(args.out) if not os.path.exists(out_dir): os.makedirs(out_dir) trajectories = sn.Trajectories() try: with open(protobuf_path, 'rb') as f: trajectories.ParseFromString(f.read()) except IOError: print('Scenenet protobuf data not found at location:{0}'.format(data_root_path)) print('Number of trajectories:{0}'.format(len(trajectories.trajectories))) all_out_path = [] for traj_no, traj in enumerate(trajectories.trajectories): layout_type = sn.SceneLayout.LayoutType.Name(traj.layout.layout_type) layout_path = traj.layout.model print('=' * 20) print('Render path:{0}'.format(traj.render_path)) print('Layout type:{0} path:{1}'.format(layout_type, layout_path)) print('=' * 20) ''' The views attribute of trajectories contains all of the information about the rendered frames of a scene. This includes camera poses, frame numbers and timestamps. ''' camera_traj = [] for view in traj.views: shutter_open = view.shutter_open camera = {'eye': [shutter_open.camera.x, shutter_open.camera.y, shutter_open.camera.z], 'at': [shutter_open.lookat.x, shutter_open.lookat.y, shutter_open.lookat.z], 'up': [0, 1, 0], # default in scenenet.proto 'proj_type': "perspective", 'viewport': [0, 0, 640, 480], 'fovy': 1.04, 'focal_length': 1.0, 'frame_no': view.frame_num, 'timestamp': shutter_open.timestamp, 'obj_path': layout_path, 'render_path': traj.render_path, "near": 0.1, "far": 1000.0 } camera_traj.append(camera) outfilename = 'traj_{}_'.format(traj_no) + traj.render_path + '_' + layout_path outfilename = outfilename.replace('/', '_').replace('.obj', '.json') assert outfilename not in all_out_path print(outfilename) with open(os.path.join(out_dir, outfilename), 'w') as fid: json.dump(camera_traj, fid) print('') all_out_path.append(outfilename)