| 417 | |
| 418 | |
| 419 | def read_model(path, ext=""): |
| 420 | # try to detect the extension automatically |
| 421 | if ext == "": |
| 422 | if detect_model_format(path, ".bin"): |
| 423 | ext = ".bin" |
| 424 | elif detect_model_format(path, ".txt"): |
| 425 | ext = ".txt" |
| 426 | else: |
| 427 | print("Provide model format: '.bin' or '.txt'") |
| 428 | return |
| 429 | |
| 430 | if ext == ".txt": |
| 431 | cameras = read_cameras_text(os.path.join(path, "cameras" + ext)) |
| 432 | images = read_images_text(os.path.join(path, "images" + ext)) |
| 433 | points3D = read_points3D_text(os.path.join(path, "points3D") + ext) |
| 434 | else: |
| 435 | cameras = read_cameras_binary(os.path.join(path, "cameras" + ext)) |
| 436 | images = read_images_binary(os.path.join(path, "images" + ext)) |
| 437 | points3D = read_points3D_binary(os.path.join(path, "points3D") + ext) |
| 438 | return cameras, images, points3D |
| 439 | |
| 440 | |
| 441 | def write_model(cameras, images, points3D, path, ext=".bin"): |