(args)
| 131 | |
| 132 | |
| 133 | def main(args): |
| 134 | # build the model |
| 135 | model = init_model(args.config, args.checkpoint, device=args.device) |
| 136 | cfg = model.cfg |
| 137 | classes = list(cfg.metainfo.classes) |
| 138 | |
| 139 | # build the data pipeline |
| 140 | test_pipeline = deepcopy(cfg.test_dataloader.dataset.pipeline) |
| 141 | test_pipeline = Compose(test_pipeline) |
| 142 | |
| 143 | # read demo data and construct model input |
| 144 | data_dir = os.path.join(args.root_dir, args.scene) |
| 145 | with open(os.path.join(data_dir, 'poses.txt'), 'r') as f: |
| 146 | poses = f.readlines() |
| 147 | |
| 148 | axis_align_matrix = np.loadtxt( |
| 149 | os.path.join(data_dir, 'axis_align_matrix.txt')) |
| 150 | intrinsic = np.loadtxt(os.path.join(data_dir, 'intrinsic.txt')) |
| 151 | intrinsic = intrinsic.astype(np.float32) |
| 152 | box_type = get_box_type('Euler-Depth') |
| 153 | info = dict( |
| 154 | axis_align_matrix=axis_align_matrix, |
| 155 | images=[], |
| 156 | img_path=[], |
| 157 | depth_img_path=[], |
| 158 | depth2img=dict(extrinsic=[], |
| 159 | intrinsic=intrinsic, |
| 160 | origin=np.array([.0, .0, .5]).astype(np.float32)), |
| 161 | depth_cam2img=intrinsic, |
| 162 | depth_shift=1000.0, |
| 163 | cam2img=intrinsic, |
| 164 | box_type_3d=box_type[0], |
| 165 | box_mode_3d=box_type[1], |
| 166 | ann_info=dict( # empty annotation |
| 167 | gt_bboxes_3d=np.zeros((0, 9), dtype=np.float32), |
| 168 | gt_labels_3d=np.zeros((0, ), dtype=np.int64), |
| 169 | visible_instance_masks=[[] for i in range(len(poses))], |
| 170 | gt_occupancy=np.zeros((0, 4), dtype=np.int64), |
| 171 | visible_occupancy_masks=[[] for i in range(len(poses))])) |
| 172 | n_frames = len(poses) |
| 173 | data = [] |
| 174 | for i in range(1, n_frames): |
| 175 | timestamp, x, y, z, qx, qy, qz, qw = poses[i].split() |
| 176 | x, y, z, qx, qy, qz, qw = float(x), float(y), float(z), float( |
| 177 | qx), float(qy), float(qz), float(qw) |
| 178 | rot_matrix = R.from_quat([qx, qy, qz, qw]).as_matrix() |
| 179 | transform_matrix = np.identity(4) |
| 180 | transform_matrix[:3, :3] = rot_matrix @ [[0, 0, 1], [-1, 0, 0], |
| 181 | [0, -1, 0]] |
| 182 | transform_matrix[:3, 3] = [x, y, z] # CAM to NOT ALIGNED GLOBAL |
| 183 | |
| 184 | image_ann = dict(img_path=os.path.join('demo', args.scene, 'rgb', |
| 185 | timestamp + '.jpg'), |
| 186 | depth_path=os.path.join('demo', args.scene, 'depth', |
| 187 | timestamp + '.png'), |
| 188 | cam2global=transform_matrix, |
| 189 | cam2img=intrinsic) |
| 190 | info['images'].append(image_ann) |
no test coverage detected