AttributeError: 'module' 对象没有属性 'xfeatures2d' [Python/OpenCV 2.4]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37039224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: 'module' object has no attribute 'xfeatures2d' [Python/OpenCV 2.4]
提问by Lipstick
This line:
这一行:
sift = cv2.xfeatures2d.SIFT_create()
return error:
返回错误:
Traceback (most recent call last):
File "C:/Python27/openCVskrypty/GUI/SOLUTION2.py", line 11, in <module>
sift = cv2.xfeatures2d.SIFT_create()
AttributeError: 'module' object has no attribute 'xfeatures2d'
I read something about this error and it appears in OpenCV version 3.0. This is quite weird because I have 2.4.11 version.
我读了一些关于这个错误的信息,它出现在 OpenCV 3.0 版中。这很奇怪,因为我有 2.4.11 版本。
I check dir(cv2) and I haven't got xfeatures2d module. Does anyone know why? Can I download it separately?
我检查了 dir(cv2) 并且我没有 xfeatures2d 模块。有谁知道为什么?可以单独下载吗?
Thanks for help how fix this.
感谢您的帮助如何解决这个问题。
回答by Shao-Kui
I think you should install opencv-contrib-python instead. The module you're using is not support in opencv-python. See opencv-contrib-python.
我认为你应该安装 opencv-contrib-python 代替。opencv-python 不支持您使用的模块。请参阅opencv-contrib-python。
To install:
安装:
pip install opencv-contrib-python
回答by Shankul Shukla
SIFT is a patented algorithm, hence not available in each open-cv version. What you can do is install opencv and its contrib part simultaneously, i.e,
SIFT 是一种获得专利的算法,因此并非在每个 open-cv 版本中都可用。您可以做的是同时安装 opencv 及其 contrib 部分,即,
pip install opencv-python==3.3.0.10 opencv-contrib-python==3.3.0.10
SIFT worked fine for me on above versions of opencv.
SIFT 在以上版本的 opencv 上对我来说效果很好。
回答by Rene B.
After executing the command:
执行命令后:
pip install opencv-contrib-python
, I got the following error:
,我收到以下错误:
error: OpenCV(4.0.0) /Users/rene/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'
错误:OpenCV(4.0.0) /Users/rene/build/skvark/opencv-python/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1207: error: (-213: The function/feature is not implementation) 这个算法已获得专利并被排除在此配置中;设置 OPENCV_ENABLE_NONFREE CMake 选项并在函数“create”中重建库
Could solve it with the following command in anaconda:
可以在 anaconda 中使用以下命令解决它:
conda install -c menpo opencv
Or with pip:
或者用点子:
pip install opencv-python==3.4.2.17
pip install opencv-contrib-python==3.4.2.17
回答by Sanjoy Kanrar
I got the same error... I have used cv2.__version__
and cv2.__path__
to check the opencv version and path. Then I removed cv2from site-packages. and install the following
我遇到了同样的错误......我已经使用cv2.__version__
并 cv2.__path__
检查了 opencv 版本和路径。然后我从site-packages 中删除了cv2。并安装以下
pip install opencv-python==3.4.2.17
pip install opencv-contrib-python==3.4.2.17
回答by Modestas Jur?ius
I used to have similar problem as @srihegde said you can try to uninstall opencv-contrib-pythonpackage and reinstall again. You can also try to uninstall opencv-pythonpackage if you have one, since it might mess with the packages too.
我曾经有类似的问题@srihegde 说你可以尝试卸载opencv-contrib-python包并重新安装。如果您有opencv-python软件包,您也可以尝试卸载它,因为它也可能与软件包混淆。
This helped for me.
这对我有帮助。
Uninstall:
卸载:
pip3 uninstall opencv-contrib-python
pip3 uninstall opencv-python
And then install:
然后安装:
pip3 install opencv-contrib-python
pip3 install opencv-python
回答by Avin_ash
I got this error and all I did was to uninstall opencv packages and install them in the following order.
我收到此错误,我所做的就是卸载 opencv 软件包并按以下顺序安装它们。
STEPS
脚步
open Anaconda Prompt
by running as administrator
and type the following commands.
open Anaconda Prompt
byrunning as administrator
并输入以下命令。
$ pip uninstall opencv-python
$ pip uninstall opencv-contrib-python
Then type the following commands
然后输入以下命令
$ pip install opencv-contrib-python==3.4.2.16
$ pip install opencv-python==3.4.2.16
This solved my problem. Hope this solves yours.!!
这解决了我的问题。希望这能解决你的问题。!!
回答by Pythonista
The problem is with your version of OpenCV. You say you're on version 2.4.11 but this version of OpenCV doesn't have this method available to it.
问题在于您的 OpenCV 版本。您说您使用的是 2.4.11 版,但是此版本的 OpenCV 没有可用的此方法。
You can check the documentation. It has features2d
您可以查看文档。它具有features2d
Whereas OpenCV 3.0 does.
而 OpenCV 3.0 可以。
回答by srihegde
This error may also occur in OpenCV 3+ as it is caused by mismatched versions of OpenCV and OpenCV-Contrib package.
此错误也可能发生在 OpenCV 3+ 中,因为它是由 OpenCV 和 OpenCV-Contrib 包的版本不匹配引起的。
I had OpenCV version 3.4.1 and OpenCV-Contrib version 3.4.0. I tried the following with OpenCV-Contrib:
我有 OpenCV 3.4.1 版和 OpenCV-Contrib 3.4.0 版。我使用 OpenCV-Contrib 尝试了以下操作:
Uninstall OpenCV-Contrib package:
卸载 OpenCV-Contrib 包:
$ pip uninstall opencv-contrib-python
Then install the same again:
然后再次安装相同的:
$ pip install opencv-contrib-python
The pip automatically fetches and installs the latest compatible version.
pip 会自动获取并安装最新的兼容版本。
回答by Harry
It doesn't work for OpenCV 4.0 due to US patent matter. Perhaps we shall give it a thumb up for this OpenSift effort:
由于美国专利问题,它不适用于 OpenCV 4.0。也许我们应该为 OpenSift 的这一努力点个赞:
回答by user3094631
You can use this instead:
您可以改用它:
sift=cv2.SIFT()