diff --git a/SuperBuild/cmake/External-OpenSfM.cmake b/SuperBuild/cmake/External-OpenSfM.cmake index b4fff241..a2d6010b 100644 --- a/SuperBuild/cmake/External-OpenSfM.cmake +++ b/SuperBuild/cmake/External-OpenSfM.cmake @@ -12,6 +12,7 @@ ExternalProject_Add(${_proj_name} GIT_TAG 200 #--Update/Patch step---------- UPDATE_COMMAND git submodule update --init --recursive + PATCH_COMMAND git apply ../../../patches/OpenSfM.diff #--Configure step------------- SOURCE_DIR ${SB_SOURCE_DIR}/${_proj_name} CONFIGURE_COMMAND cmake /${_proj_name}/src diff --git a/patches/OpenSfM.diff b/patches/OpenSfM.diff new file mode 100644 index 00000000..5d7bb5a8 --- /dev/null +++ b/patches/OpenSfM.diff @@ -0,0 +1,47 @@ +diff --git a/opensfm/context.py b/opensfm/context.py +index a01dd700..f54fcf87 100644 +--- a/opensfm/context.py ++++ b/opensfm/context.py +@@ -17,6 +17,9 @@ BOW_PATH = os.path.join(abspath, 'data', 'bow') + + + # Handle different OpenCV versions ++OPENCV5 = int(cv2.__version__.split('.')[0]) >= 5 #future proofing SIFT support test (see features.py) ++OPENCV4 = int(cv2.__version__.split('.')[0]) >= 4 ++OPENCV44 = int(cv2.__version__.split('.')[0]) == 4 and int(cv2.__version__.split('.')[1]) >= 4 # for SIFT support (see features.py) + OPENCV3 = int(cv2.__version__.split('.')[0]) >= 3 + + if hasattr(cv2, 'flann_Index'): +diff --git a/opensfm/features.py b/opensfm/features.py +index 3e80224b..78e51ce5 100644 +--- a/opensfm/features.py ++++ b/opensfm/features.py +@@ -87,7 +87,13 @@ def _in_mask(point, width, height, mask): + def extract_features_sift(image, config): + sift_edge_threshold = config['sift_edge_threshold'] + sift_peak_threshold = float(config['sift_peak_threshold']) +- if context.OPENCV3: ++ # SIFT support is in cv2 main from version 4.4.0 ++ if context.OPENCV44 or context.OPENCV5: ++ detector = cv2.SIFT_create( ++ edgeThreshold=sift_edge_threshold, ++ contrastThreshold=sift_peak_threshold) ++ descriptor = detector ++ elif context.OPENCV3: + try: + detector = cv2.xfeatures2d.SIFT_create( + edgeThreshold=sift_edge_threshold, +@@ -105,7 +110,12 @@ def extract_features_sift(image, config): + while True: + logger.debug('Computing sift with threshold {0}'.format(sift_peak_threshold)) + t = time.time() +- if context.OPENCV3: ++ # SIFT support is in cv2 main from version 4.4.0 ++ if context.OPENCV44 or context.OPENCV5: ++ detector = cv2.SIFT_create( ++ edgeThreshold=sift_edge_threshold, ++ contrastThreshold=sift_peak_threshold) ++ elif context.OPENCV3: + detector = cv2.xfeatures2d.SIFT_create( + edgeThreshold=sift_edge_threshold, + contrastThreshold=sift_peak_threshold)