Skip to content

Commit

Permalink
Adaptive feature quality
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Oct 29, 2023
1 parent a06f6f1 commit 52fa5d1
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions opendm/osfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from opendm import context
from opendm import camera
from opendm import location
from opendm.photo import find_largest_photo_dim, find_largest_photo
from opendm.photo import find_largest_photo_dims, find_largest_photo
from opensfm.large import metadataset
from opensfm.large import tools
from opensfm.actions import undistort
Expand Down Expand Up @@ -211,11 +211,25 @@ def setup(self, args, images_path, reconstruction, append_config = [], rerun=Fal
'lowest': 0.0675,
}

max_dim = find_largest_photo_dim(photos)
max_dims = find_largest_photo_dims(photos)

if max_dim > 0:
if max_dims is not None:
w, h = max_dims
max_dim = max(w, h)
log.ODM_INFO("Maximum photo dimensions: %spx" % str(max_dim))
feature_process_size = int(max_dim * feature_quality_scale[args.feature_quality])

lower_limit = 320
upper_limit = 4480
megapixels = (w * h) / 1e6
multiplier = 1

if megapixels < 2:
multiplier = 2
elif megapixels > 42:
multiplier = 0.5

factor = min(1, feature_quality_scale[args.feature_quality] * multiplier)
feature_process_size = min(upper_limit, max(lower_limit, int(max_dim * factor)))
log.ODM_INFO("Photo dimensions for feature extraction: %ipx" % feature_process_size)
else:
log.ODM_WARNING("Cannot compute max image dimensions, going with defaults")
Expand Down Expand Up @@ -283,9 +297,8 @@ def setup(self, args, images_path, reconstruction, append_config = [], rerun=Fal
config.append("matcher_type: %s" % osfm_matchers[matcher_type])

# GPU acceleration?
if has_gpu(args):
max_photo = find_largest_photo(photos)
w, h = max_photo.width, max_photo.height
if has_gpu(args) and max_dims is not None:
w, h = max_dims
if w > h:
h = int((h / w) * feature_process_size)
w = int(feature_process_size)
Expand Down

0 comments on commit 52fa5d1

Please sign in to comment.