Skip to content

Commit

Permalink
updated export to openmvg and export to db to read camera option file
Browse files Browse the repository at this point in the history
  • Loading branch information
franioli committed Apr 13, 2024
1 parent b8970ea commit 3ef8dae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 2 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
feature_path, match_path = matcher.run()

# Export in colmap format
with open(config.general["camera_options"], "r") as file:
camera_options = yaml.safe_load(file)
database_path = output_dir / "database.db"
dim.io.export_to_colmap(
img_dir=imgs_dir,
feature_path=feature_path,
match_path=match_path,
database_path=database_path,
camera_options=camera_options,
camera_config_path=config.general["camera_options"],
)

# Visualize view graph
Expand All @@ -56,7 +54,7 @@
openmvg_out_path=openmvg_out_path,
openmvg_sfm_bin=openmvg_sfm_bin,
openmvg_database=openmvg_database,
camera_options=camera_options,
camera_config_path=config.general["camera_options"],
)

# Reconstruction with OpenMVG
Expand Down
4 changes: 2 additions & 2 deletions src/deep_image_matching/io/h5_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

logger = logging.getLogger("dim")

default_camera_options = {
DEFAULT_CAM_OPTIONS = {
"general": {
"single_camera": False,
"camera_model": "simple-radial",
Expand Down Expand Up @@ -85,7 +85,7 @@ def export_to_colmap(
with open(camera_config_path, "r") as file:
camera_options = yaml.safe_load(file)
else:
camera_options = default_camera_options
camera_options = DEFAULT_CAM_OPTIONS

# Create the database and add keypoints and matches
db = COLMAPDatabase.connect(database_path)
Expand Down
28 changes: 26 additions & 2 deletions src/deep_image_matching/io/h5_to_openmvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import h5py
import numpy as np
import yaml
from PIL import Image
from tqdm import tqdm

Expand All @@ -26,6 +27,13 @@
"pinhole_brown_t2": "disto_t2",
}

DEFAULT_CAM_OPTIONS = {
"general": {
"single_camera": False,
"openmvg_camera_model": "pinhole_radial_k3",
},
}


def loadJSON(sfm_data):
with open(sfm_data) as file:
Expand Down Expand Up @@ -331,7 +339,7 @@ def export_to_openmvg(
feature_path: Path,
match_path: Path,
openmvg_out_path: Path,
camera_options: dict,
camera_config_path: Path,
openmvg_sfm_bin: Path = None,
openmvg_database: Path = None,
) -> None:
Expand All @@ -345,7 +353,7 @@ def export_to_openmvg(
feature_path (Path): Path to the feature file (HDF5 format).
match_path (Path): Path to the match file (HDF5 format).
openmvg_out_path (Path): Path to the desired output directory for the OpenMVG project.
camera_options (dict): Camera configuration options.
camera_config_path (Path): Path to the camera options yaml file.
openmvg_sfm_bin (Path, optional): Path to the OpenMVG SfM executable. If not provided,
attempts to find it automatically (Linux only).
openmvg_database (Path, optional): Path to the OpenMVG sensor width database.
Expand All @@ -358,6 +366,22 @@ def export_to_openmvg(
os.rmdir(openmvg_out_path)
openmvg_out_path.mkdir(parents=True)

if not img_dir.exists():
raise FileNotFoundError(f"Image directory {img_dir} does not exist.")
if not feature_path.exists():
raise FileNotFoundError(f"Feature file {feature_path} does not exist.")
if not match_path.exists():
raise FileNotFoundError(f"Match file {match_path} does not exist.")
if not camera_config_path.exists():
raise FileNotFoundError(f"Camera options file {camera_config_path} does not exist.")

# If a config file is provided, read camera options, otherwise use defaults
if camera_config_path is not None:
with open(camera_config_path, "r") as file:
camera_options = yaml.safe_load(file)
else:
camera_options = DEFAULT_CAM_OPTIONS

# NOTE: this part meybe is not needed here...
if openmvg_sfm_bin is None:
# Try to find openMVG binaries (only on linux)
Expand Down

0 comments on commit 3ef8dae

Please sign in to comment.