import sys import os import json import argparse from typing import Mapping sys.path.append(os.path.abspath(sys.path[0] + '/../')) from utils import view parser = argparse.ArgumentParser() parser.add_argument('-o', '--output', type=str, default='') parser.add_argument('dataset', type=str) args = parser.parse_args() data_desc_path = args.dataset data_desc_name = os.path.splitext(os.path.basename(data_desc_path))[0] data_dir = os.path.dirname(data_desc_path) + '/' with open(data_desc_path, 'r') as fp: dataset_desc: Mapping = json.load(fp) dataset_desc['cam_params'] = view.CameraParam.convert_camera_params( dataset_desc['cam_params'], (dataset_desc['view_res']['x'], dataset_desc['view_res']['x'])) dataset_desc['view_rots'] = [ view.euler_to_matrix([rot[1], rot[0], 0]) for rot in dataset_desc['view_rots'] ] if len(dataset_desc['view_rots'][0]) == 2 else dataset_desc['view_rots'] if dataset_desc.get('gl_coord'): del dataset_desc['gl_coord'] for i in range(len(dataset_desc['view_centers'])): dataset_desc['view_centers'][i][2] *= -1 dataset_desc['view_rots'][i][2] *= -1 dataset_desc['view_rots'][i][5] *= -1 dataset_desc['view_rots'][i][6] *= -1 dataset_desc['view_rots'][i][7] *= -1 output_name = args.output if args.output else data_desc_name + '_cvt.json' with open(os.path.join(data_dir, output_name), 'w') as fp: json.dump(dataset_desc, fp, indent=4)