Issues with Configuring/Building OpenCV 4.6.0 with SFM contrib Module in macOS m1

Hi. I am attempting to build OpenCV 4.6.0 with SFM module only for macOS arm64 architecture . Per the installation page for the SFM module, the dependencies are of the following:

  • Eigen 3.2.2 or later
  • Ceres
  • glog
  • gflags

For starters, I built a Ceres static library v2.1 with the following configuration:

  • Eigen 3.4.0 installed via homebrew
  • Using EigenSparse
  • No SuiteSparse
  • No CXSparse
  • Using gflags v2.2.2 built from source
  • Using glog v0.6.0 built from source

I then ran the sample binaries that were built and results were passing and no crashes just to verify it works.

With that, I used CMake GUI for OpenCV 4.6.0 config and set the Ceres_DIR variable to the directory with the CMake config file for Ceres, same goes for glog_DIR, Gflags_DIR, and gflags_DIR. For OPENCV_EXTRA_MODULES_PATH, I then set the value to the directory for the sfm module (*/opencv_contrib-4.6.0/modules/sfm) and pressed the Configure button.

The issue arose when I get the following CMake config output:

ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
Detected processor: arm64
Looking for ccache - not found
libjpeg-turbo: VERSION = 2.1.2, BUILD = opencv-4.6.0-libjpeg-turbo
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.6.0-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version “2.4.0”)
LAPACK(LAPACK/Apple): LAPACK_LIBRARIES: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Accelerate.framework;-lm;-ldl
LAPACK(LAPACK/Apple): Support is enabled.
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT)
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
CMake Deprecation Warning at 3rdparty/carotene/hal/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.

Update the VERSION argument value or use a … suffix to tell
CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at 3rdparty/carotene/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.

Update the VERSION argument value or use a … suffix to tell
CMake that the project does not need compatibility with older versions.

CMake Error at cmake/OpenCVModule.cmake:274 (message):
No modules has been found: /Users/me_user/Documents/Open Source Libs -
Source/opencv-4.6.0/ /Users/me_user/Documents/Open Source Libs -
Source/opencv_contrib-4.6.0/modules/xfeatures2d
Call Stack (most recent call first):
cmake/OpenCVModule.cmake:356 (_glob_locations)
cmake/OpenCVModule.cmake:385 (ocv_glob_modules)
CMakeLists.txt:931 (ocv_register_modules)

Checking for modules ‘libavcodec;libavformat;libavutil;libswscale’
No package ‘libavcodec’ found
No package ‘libavformat’ found
No package ‘libavutil’ found
No package ‘libswscale’ found
FFMPEG is disabled. Required libraries: libavcodec;libavformat;libavutil;libswscale. Missing libraries: libavcodec;libavformat;libavutil;libswscale
Checking for module ‘gstreamer-base-1.0’
No package ‘gstreamer-base-1.0’ found
Checking for module ‘gstreamer-app-1.0’
No package ‘gstreamer-app-1.0’ found
Checking for module ‘gstreamer-riff-1.0’
No package ‘gstreamer-riff-1.0’ found
Checking for module ‘gstreamer-pbutils-1.0’
No package ‘gstreamer-pbutils-1.0’ found
Checking for module ‘gstreamer-video-1.0’
No package ‘gstreamer-video-1.0’ found
Checking for module ‘gstreamer-audio-1.0’
No package ‘gstreamer-audio-1.0’ found
Checking for module ‘libdc1394-2’
No package ‘libdc1394-2’ found
Module opencv_sfm disabled because opencv_xfeatures2d dependency can’t be resolved!

I wasn’t aware OpenCV sfm module needs xfeatures2d to be built. Am I missing something here? I am worried that this might become a dependency hell kind of problem should I continue to proceed with including xfeatures2d module in the build. That, and I’m not interested with using non-free 2D feature algorithms. If there is anyone here experienced with building/using SFM module, any guidance or assistance would be appreciated. Thank you.

the reconstruction part uses DAISY or LATCH features from xfeatures2d

those are only enabled, if OPENCV_ENABLE_NONFREE=ON, and there are a lot more algorithms in there, apart from the nonfree ones

tl;dr: i’m afraid, you’ll have to bite the sour apple, and build with the xfeatures2d module for this

Hi, Berak. Thanks for the input. Will put in xfeatures2D if that’s the case.