From 2fea4d9f3dcac0a98c45070895b46a1196b0a7e3 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 8 Sep 2023 13:12:52 -0400 Subject: [PATCH] More memory efficient find_features_homography --- opendm/multispectral.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/opendm/multispectral.py b/opendm/multispectral.py index dddcb3db..0fcdb838 100644 --- a/opendm/multispectral.py +++ b/opendm/multispectral.py @@ -504,6 +504,28 @@ def find_features_homography(image_gray, align_image_gray, feature_retention=0.7 # Detect SIFT features and compute descriptors. detector = cv2.SIFT_create(edgeThreshold=10, contrastThreshold=0.1) + + h,w = image_gray.shape + max_dim = max(h, w) + + max_size = 1280 + if max_dim > max_size: + if max_dim == w: + f = max_size / w + else: + f = max_size / h + image_gray = cv2.resize(image_gray, None, fx=f, fy=f, interpolation=cv2.INTER_AREA) + h,w = image_gray.shape + + if align_image_gray.shape[0] != image_gray.shape[0]: + fx = image_gray.shape[1]/align_image_gray.shape[1] + fy = image_gray.shape[0]/align_image_gray.shape[0] + + align_image_gray = cv2.resize(align_image_gray, None, + fx=fx, + fy=fy, + interpolation=(cv2.INTER_AREA if (fx < 1.0 and fy < 1.0) else cv2.INTER_LANCZOS4)) + kp_image, desc_image = detector.detectAndCompute(image_gray, None) kp_align_image, desc_align_image = detector.detectAndCompute(align_image_gray, None)