(path, ext="")
| 419 | |
| 420 | |
| 421 | def read_model(path, ext=""): |
| 422 | # try to detect the extension automatically |
| 423 | if ext == "": |
| 424 | if detect_model_format(path, ".bin"): |
| 425 | ext = ".bin" |
| 426 | elif detect_model_format(path, ".txt"): |
| 427 | ext = ".txt" |
| 428 | else: |
| 429 | try: |
| 430 | cameras, images, points3D = read_model(os.path.join(path, "model/")) |
| 431 | logger.warning( |
| 432 | "This SfM file structure was deprecated in hloc v1.1") |
| 433 | return cameras, images, points3D |
| 434 | except FileNotFoundError: |
| 435 | raise FileNotFoundError( |
| 436 | f"Could not find binary or text COLMAP model at {path}") |
| 437 | |
| 438 | if ext == ".txt": |
| 439 | cameras = read_cameras_text(os.path.join(path, "cameras" + ext)) |
| 440 | images = read_images_text(os.path.join(path, "images" + ext)) |
| 441 | points3D = read_points3D_text(os.path.join(path, "points3D") + ext) |
| 442 | else: |
| 443 | cameras = read_cameras_binary(os.path.join(path, "cameras" + ext)) |
| 444 | images = read_images_binary(os.path.join(path, "images" + ext)) |
| 445 | points3D = read_points3D_binary(os.path.join(path, "points3D") + ext) |
| 446 | return cameras, images, points3D |
| 447 | |
| 448 | |
| 449 | def write_model(cameras, images, points3D, path, ext=".bin"): |
no test coverage detected