Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module 'cv2' has no attribute 'sfm' #3746

Open
cultist123 opened this issue May 26, 2024 · 2 comments
Open

module 'cv2' has no attribute 'sfm' #3746

cultist123 opened this issue May 26, 2024 · 2 comments
Labels
category: build/install question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org/

Comments

@cultist123
Copy link

  • OpenCV => 4.8.0

  • Operating System / Platform => MacOS M2M214.1

  • Compiler => terminal

  • Compiler => cmake

I have installed all the necessary dependencies according to https://docs.opencv.org/4.x/db/db8/tutorial_sfm_installation.html and successfully compiled and installed them. However, when I run import cv2; help(cv2.sfm) in the terminal, it keeps showing module 'cv2' has no attribute 'sfm'. Similarly, when trying other modules like 'face', it also outputs something like module 'cv2' has no attribute 'face'. I suspect it's an issue with the site-package, so I changed the Python path to point to the site-package directory. I'm not sure if what I did is correct. Below are the outputs from my cmake and Python3.

Detected processor: arm64
Looking for ccache - not found
libjpeg-turbo: VERSION = 2.1.3, BUILD = opencv-4.8.0-libjpeg-turbo
Use full Neon SIMD intrinsics implementation (NEON_INTRINSICS = ON)
SIMD extensions: arm64 (WITH_SIMD = 1)
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.8.0-openjp2-2.5.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
LAPACK(LAPACK/Apple): LAPACK_LIBRARIES: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.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)
Found VTK 9.3.0
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
freetype2: YES (ver 26.1.20)
harfbuzz: YES (ver 8.4.0)
Julia not found. Not compiling Julia Bindings.
Module opencv_ovis disabled because OGRE3D was not found
Found AMD headers in: /opt/homebrew/include/suitesparse
Found AMD library: /opt/homebrew/lib/libamd.dylib
Found CAMD headers in: /opt/homebrew/include/suitesparse
Found CAMD library: /opt/homebrew/lib/libcamd.dylib
Found CCOLAMD headers in: /opt/homebrew/include/suitesparse
Found CCOLAMD library: /opt/homebrew/lib/libccolamd.dylib
Found CHOLMOD headers in: /opt/homebrew/include/suitesparse
Found CHOLMOD library: /opt/homebrew/lib/libcholmod.dylib
Found COLAMD headers in: /opt/homebrew/include/suitesparse
Found COLAMD library: /opt/homebrew/lib/libcolamd.dylib
Found SPQR headers in: /opt/homebrew/include/suitesparse
Found SPQR library: /opt/homebrew/lib/libspqr.dylib
Found Config headers in: /opt/homebrew/include/suitesparse
Found Config library: /opt/homebrew/lib/libsuitesparseconfig.dylib
Found Intel Thread Building Blocks (TBB) library (2021.12 / ) include location: . Assuming SuiteSparseQR was compiled with TBB.
Could not find librt, but found SuiteSparse_config, assuming that SuiteSparse was compiled without timing.
Checking for module 'tesseract'
No package 'tesseract' found
Tesseract: NO
Allocator metrics storage type: 'int'
Excluding from source files list: /modules/core/test/test_intrin128.sse2.cpp
Excluding from source files list: /modules/core/test/test_intrin128.sse3.cpp
Excluding from source files list: /modules/core/test/test_intrin128.ssse3.cpp
Excluding from source files list: /modules/core/test/test_intrin128.sse4_1.cpp
Excluding from source files list: /modules/core/test/test_intrin128.sse4_2.cpp
Excluding from source files list: /modules/core/test/test_intrin128.avx.cpp
Excluding from source files list: /modules/core/test/test_intrin128.avx2.cpp
Excluding from source files list: /modules/core/test/test_intrin128.avx512_skx.cpp
Excluding from source files list: /modules/core/test/test_intrin256.avx2.cpp
Excluding from source files list: /modules/core/test/test_intrin256.avx512_skx.cpp
Excluding from source files list: /modules/core/test/test_intrin512.avx512_skx.cpp
Excluding from source files list: modules/imgproc/src/corner.avx.cpp
Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
Excluding from source files list: modules/imgproc/src/imgwarp.sse4_1.cpp
Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
Excluding from source files list: modules/imgproc/src/resize.sse4_1.cpp
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /Users/apple/Documents/2 工作空间/git/opencv/source/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
opencv_dnn: filter out ocl4dnn source code
opencv_dnn: filter out cuda4dnn source code
Excluding from source files list: /modules/dnn/layers/layers_common.avx.cpp
Excluding from source files list: /modules/dnn/layers/layers_common.avx2.cpp
Excluding from source files list: /modules/dnn/layers/layers_common.avx512_skx.cpp
Excluding from source files list: /modules/dnn/layers/layers_common.rvv.cpp
Excluding from source files list: /modules/dnn/layers/layers_common.lasx.cpp
Excluding from source files list: /modules/dnn/int8layers/layers_common.avx2.cpp
Excluding from source files list: /modules/dnn/int8layers/layers_common.avx512_skx.cpp
Excluding from source files list: /modules/dnn/int8layers/layers_common.lasx.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_block.avx.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_block.avx2.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_depthwise.avx.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_depthwise.avx2.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_winograd_f63.avx.cpp
Excluding from source files list: /modules/dnn/layers/cpu_kernels/conv_winograd_f63.avx2.cpp
Excluding from source files list: modules/features2d/src/fast.avx2.cpp
imgcodecs: OpenEXR codec is disabled in runtime. Details: opencv/opencv#21326
highgui: using builtin backend: COCOA
Found AMD headers in: /opt/homebrew/include/suitesparse
Found AMD library: /opt/homebrew/lib/libamd.dylib
Found CAMD headers in: /opt/homebrew/include/suitesparse
Found CAMD library: /opt/homebrew/lib/libcamd.dylib
Found CCOLAMD headers in: /opt/homebrew/include/suitesparse
Found CCOLAMD library: /opt/homebrew/lib/libccolamd.dylib
Found CHOLMOD headers in: /opt/homebrew/include/suitesparse
Found CHOLMOD library: /opt/homebrew/lib/libcholmod.dylib
Found COLAMD headers in: /opt/homebrew/include/suitesparse
Found COLAMD library: /opt/homebrew/lib/libcolamd.dylib
Found SPQR headers in: /opt/homebrew/include/suitesparse
Found SPQR library: /opt/homebrew/lib/libspqr.dylib
Found Config headers in: /opt/homebrew/include/suitesparse
Found Config library: /opt/homebrew/lib/libsuitesparseconfig.dylib
Found Intel Thread Building Blocks (TBB) library (2021.12 / ) include location: . Assuming SuiteSparseQR was compiled with TBB.
Could not find librt, but found SuiteSparse_config, assuming that SuiteSparse was compiled without timing.
Found 'misc' Python modules from /Users/apple/Documents/2 工作空间/git/opencv/source/opencv/modules/python/package/extra_modules
Found 'mat_wrapper;utils' Python modules from /Users/apple/Documents/2 工作空间/git/opencv/source/opencv/modules/core/misc/python/package
Found 'gapi' Python modules from /Users/apple/Documents/2 工作空间/git/opencv/source/opencv/modules/gapi/misc/python/package
SYCL/OpenCL samples are skipped: SYCL SDK is required

  • check configuration of SYCL_DIR/SYCL_ROOT/CMAKE_MODULE_PATH
  • ensure that right compiler is selected from SYCL SDK (e.g, clang++): CMAKE_CXX_COMPILER=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++

General configuration for OpenCV 4.8.0 =====================================
Version control: ddadcee-dirty

Extra modules:
Location (extra): /Users/apple/Documents/2 工作空间/git/opencv/source/opencv_contrib/modules
Version control (extra): ddadcee-dirty

Platform:
Timestamp: 2024-05-26T15:09:36Z
Host: Darwin 23.1.0 arm64
CMake: 3.26.3
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: Release

CPU/HW features:
Baseline: NEON FP16

C/C++:
Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (ver 15.0.0.15000309)
C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -g -O0 -DDEBUG -D_DEBUG
C Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,-dead_strip
Linker flags (Debug): -Wl,-dead_strip
ccache: NO
Precompiled headers: NO
Extra dependencies:
3rdparty dependencies:

OpenCV modules:
To be built: alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab viz wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
Disabled: world
Disabled by dependency: -
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv java julia matlab ovis python2 python3
Applications: tests perf_tests examples apps
Documentation: NO
Non-free algorithms: NO

GUI: COCOA
Cocoa: YES
VTK support: YES (ver 9.3.0)

Media I/O:
ZLib: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libz.tbd (ver 1.2.12)
JPEG: build-libjpeg-turbo (ver 2.1.3-62)
SIMD Support Request: YES
SIMD Support: YES
WEBP: build (ver encoder: 0x020f)
PNG: libpng (ver 1.6.37)
TIFF: libtiff (ver 42 / 4.2.0)
JPEG 2000: build (ver 2.5.0)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES

Video I/O:
DC1394: NO
FFMPEG: NO
avcodec: NO
avformat: NO
avutil: NO
swscale: NO
avresample: NO
GStreamer: NO
AVFoundation: YES

Parallel framework: GCD

Trace: YES (with Intel ITT)

Other third-party libraries:
Lapack: YES (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl)
Eigen: YES (ver 3.4.0)
Custom HAL: YES (carotene (ver 0.0.1))
Protobuf: build (3.19.1)
Flatbuffers: builtin/3rdparty (23.5.9)

OpenCL: YES (no extra features)
Include path: NO
Link libraries: -framework OpenCL

Python (for build): /usr/bin/python3.10

Java:
ant: NO
Java: YES (ver 1.8.0.401)
JNI: NO
Java wrappers: NO
Java tests: NO

Install to: /usr/local

Configuring done (8.9s)
Generating done (3.1s)

import cv2
help(cv2.sfm)
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'cv2' has no attribute 'sfm'

@opencv-alalek opencv-alalek added question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org/ category: build/install labels May 27, 2024
@opencv-alalek
Copy link

Your local build doesn't include Python binding.
In your environment import cv2 uses something else (check through cv2.__file__ and getBuildInformation()).

Build / usage questions should go to Users OpenCV Q/A forum: https://forum.opencv.org/

@Ritikyadav1
Copy link

Check OpenCV Extra Modules:
Ensure that you have the opencv_contrib repository cloned and properly configured. The extra modules like sfm and face are part of the opencv_contrib modules.

Set Up CMake:
When configuring OpenCV with CMake, ensure you include the path to the opencv_contrib modules. Here’s an example command to configure OpenCV with the extra modules:

cd /path/to/opencv/build
cmake -DOPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib/modules ..

Rebuild OpenCV:
After configuring CMake, rebuild and install OpenCV:

make -j8 # adjust -j8 to the number of cores in your CPU

sudo make install
Verify Installation:
Ensure that the installation paths are correctly set up and that Python is using the correct OpenCV package. You can verify this by checking the installation directory:

python3 -c "import cv2; print(cv2.file)"
This should point to your newly built OpenCV installation.

Python Path Configuration:
Ensure that your Python environment is using the correct OpenCV site-package. Sometimes, multiple installations can cause conflicts. Update your PYTHONPATH to include the correct directory:

export PYTHONPATH=/usr/local/lib/python3.10/site-packages:$PYTHONPATH
Check Installed Modules:
You can list the installed modules in the OpenCV package to ensure that sfm and face are included:

python3 -c "import cv2; print(dir(cv2))"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build/install question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org/
Projects
None yet
Development

No branches or pull requests

3 participants