Skip to content

Commit

Permalink
updated imports to avoid crashes with no pycolmap
Browse files Browse the repository at this point in the history
  • Loading branch information
franioli committed Mar 30, 2024
1 parent 7433e77 commit 6cea00d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/deep_image_matching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
__version__ = "1.0.0"

import logging

# Check if pycolmap is installed
try:
import pycolmap

NO_PYCOLMAP = False
except ImportError:
logging.warning(
"pycolmap is not installed, some advanced features may not work, but you will be able to run deep-image-matching and export the matched features in a sqlite3 database to be opened in COLMAP GUI."
)
NO_PYCOLMAP = True

# Import submodules
from . import io
from . import utils
from . import reconstruction
from . import triangulation
from . import extractors
from . import matchers

if not NO_PYCOLMAP:
from . import triangulation # the triangulation module strictly requires pycolmap

# Import functions
from .parser import parse_cli

Expand Down
12 changes: 11 additions & 1 deletion src/deep_image_matching/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@
from .logger import change_logger_level, setup_logger
from .tiling import Tiler
from .timer import Timer, timeit
from .utils import *
from .utils import OutputCapture, get_pairs_from_file, to_homogeneous

try:
import pycolmap

NO_PYCOLMAP = False
except ImportError:
NO_PYCOLMAP = True

if not NO_PYCOLMAP:
from .utils import compute_epipolar_errors
8 changes: 2 additions & 6 deletions src/deep_image_matching/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
from typing import Dict

import numpy as np
import pycolmap

from .database import COLMAPDatabase

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger = logging.getLogger("dim")


class OutputCapture:
Expand Down Expand Up @@ -90,7 +86,7 @@ def vector_to_cross_product_matrix(v):
return np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])


def compute_epipolar_errors(j_from_i: pycolmap.Rigid3d, p2d_i, p2d_j):
def compute_epipolar_errors(j_from_i, p2d_i, p2d_j):
"""
Computes epipolar errors for corresponding 2D points between two images.
Expand Down

0 comments on commit 6cea00d

Please sign in to comment.