opencvのsift特徴量を求めるライブラリを使用したいので、contribをインストールしようとしたら、homebrew自体がインストールオプションをなくしていたので、opencv3全体をインストールしたものの、SIFTがまだありません。。。
同じような状況に陥った方、対処法を知っている方、いらっしゃいましたら是非ご教授ください。
宜しくお願い致します。
python
1import numpy 2import cv2 3 4sift = cv2.SIFT() 5 6 7↓Error↓ 8Traceback (most recent call last): 9 File "test.py", line 166, in <module> 10 sift = cv2.SIFT() 11AttributeError: module 'cv2.cv2' has no attribute 'SIFT'
console
1$ brew install opencv3 --with-contrib 2Usage: brew install [options] formula 3 4Install formula. Additional options specific to formula may be appended to 5the command. 6 7Unless HOMEBREW_NO_INSTALL_CLEANUP is set, brew cleanup will then be run for 8the installed formulae or, every 30 days, for all formulae. 9 10 -d, --debug If brewing fails, open an interactive 11 debugging session with access to IRB or a 12 shell inside the temporary build directory. 13 --env If std is passed, use the standard build 14 environment instead of superenv. If super 15 is passed, use superenv even if the formula 16 specifies the standard build environment. 17 --ignore-dependencies An unsupported Homebrew development flag to 18 skip installing any dependencies of any 19 kind. If the dependencies are not already 20 present, the formula will have issues. If 21 you're not developing Homebrew, consider 22 adjusting your PATH rather than using this 23 flag. 24 --only-dependencies Install the dependencies with specified 25 options but do not install the formula 26 itself. 27 --cc Attempt to compile using the specified 28 compiler, which should be the name of the 29 compiler's executable, e.g. gcc-7 for GCC 30 7. In order to use LLVM's clang, specify 31 llvm_clang. To use the Apple-provided 32 clang, specify clang. This option will 33 only accept compilers that are provided by 34 Homebrew or bundled with macOS. Please do 35 not file issues if you encounter errors 36 while using this option. 37 -s, --build-from-source Compile formula from source even if a 38 bottle is provided. Dependencies will still 39 be installed from bottles if they are 40 available. 41 --force-bottle Install from a bottle if it exists for the 42 current or newest version of macOS, even if 43 it would not normally be used for 44 installation. 45 --include-test Install testing dependencies required to 46 run brew test formula. 47 --devel If formula defines it, install the 48 development version. 49 --HEAD If formula defines it, install the HEAD 50 version, aka. master, trunk, unstable. 51 --fetch-HEAD Fetch the upstream repository to detect if 52 the HEAD installation of the formula is 53 outdated. Otherwise, the repository's HEAD 54 will only be checked for updates when a new 55 stable or development version has been 56 released. 57 --keep-tmp Retain the temporary files created during 58 installation. 59 --build-bottle Prepare the formula for eventual bottling 60 during installation, skipping any 61 post-install steps. 62 --bottle-arch Optimise bottles for the specified 63 architecture rather than the oldest 64 architecture supported by the version of 65 macOS the bottles are built on. 66 -f, --force Install without checking for previously 67 installed keg-only or non-migrated 68 versions. 69 -v, --verbose Print the verification and postinstall 70 steps. 71 --display-times Print install times for each formula at the 72 end of the run. 73 -i, --interactive Download and patch formula, then open a 74 shell. This allows the user to run 75 ./configure --help and otherwise 76 determine how to turn the software package 77 into a Homebrew package. 78 -g, --git Create a Git repository, useful for 79 creating patches to the software. 80 -h, --help Show this message. 81Error: invalid option: --with-contrib
OpenCV 3からAPI が
sift = cv2.xfeatures2d.SIFT_create()
に変更されたようです。
返信有難うございます。
それも試して、同じエラーが出たので、もう一度消して入れ直してみようと思います!
入れ直して、試してみたところ、以下のようなエラーが出ました。
この場合、実行する際に、以下のOPENCV_ENABLE_NONFREEオプションを付ければ良いのでしょうか?
cv2.error: OpenCV(4.1.1) /Users/travis/build/skvark/opencv-python/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'
自分は Mac 環境はないため、brew でどうなるかはわからなかったのですが、pip で入れた場合も同じようになります。原因については長くなるので回答に記載しました。
ソースビルドすれば使えるようになるわけですが、cmake 等の知識が必要になるため、AKAZE など今インストールしてある OpenCV でも使える特徴量を使用されてはどうでしょうか
回答2件
あなたの回答
tips
プレビュー