(realdir)
| 10 | |
| 11 | |
| 12 | def load_colmap_data(realdir): |
| 13 | |
| 14 | camerasfile = os.path.join(realdir, 'sparse/0/cameras.bin') |
| 15 | camdata = read_model.read_cameras_binary(camerasfile) |
| 16 | |
| 17 | # cam = camdata[camdata.keys()[0]] |
| 18 | list_of_keys = list(camdata.keys()) |
| 19 | cam = camdata[list_of_keys[0]] |
| 20 | print( 'Cameras', len(cam)) |
| 21 | |
| 22 | h, w, f = cam.height, cam.width, cam.params[0] |
| 23 | # w, h, f = factor * w, factor * h, factor * f |
| 24 | hwf = np.array([h,w,f]).reshape([3,1]) |
| 25 | |
| 26 | imagesfile = os.path.join(realdir, 'sparse/0/images.bin') |
| 27 | imdata = read_model.read_images_binary(imagesfile) |
| 28 | |
| 29 | w2c_mats = [] |
| 30 | bottom = np.array([0,0,0,1.]).reshape([1,4]) |
| 31 | |
| 32 | names = [imdata[k].name for k in imdata] |
| 33 | print( 'Images #', len(names)) |
| 34 | perm = np.argsort(names) |
| 35 | for k in imdata: |
| 36 | im = imdata[k] |
| 37 | R = im.qvec2rotmat() |
| 38 | t = im.tvec.reshape([3,1]) |
| 39 | m = np.concatenate([np.concatenate([R, t], 1), bottom], 0) |
| 40 | w2c_mats.append(m) |
| 41 | |
| 42 | w2c_mats = np.stack(w2c_mats, 0) |
| 43 | c2w_mats = np.linalg.inv(w2c_mats) |
| 44 | |
| 45 | poses = c2w_mats[:, :3, :4].transpose([1,2,0]) |
| 46 | poses = np.concatenate([poses, np.tile(hwf[..., np.newaxis], [1,1,poses.shape[-1]])], 1) |
| 47 | |
| 48 | points3dfile = os.path.join(realdir, 'sparse/0/points3D.bin') |
| 49 | pts3d = read_model.read_points3d_binary(points3dfile) |
| 50 | |
| 51 | # must switch to [-u, r, -t] from [r, -u, t], NOT [r, u, -t] |
| 52 | poses = np.concatenate([poses[:, 1:2, :], poses[:, 0:1, :], -poses[:, 2:3, :], poses[:, 3:4, :], poses[:, 4:5, :]], 1) |
| 53 | |
| 54 | return poses, pts3d, perm |
| 55 | |
| 56 | |
| 57 | def save_poses(basedir, poses, pts3d, perm): |
no test coverage detected