我正在尝试使用 SIFT 与 Python 进行特征检测,但它不再是 OpenCV 的一部分orOpenCV 贡献。
使用 OpenCV opencv-contrib-python (两个版本 4.2.0.34,这个问题的最新版本),我得到:
>>> import cv2
>>> cv2.SIFT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'SIFT_create'
>>> cv2.xfeatures2d.SIFT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1210:
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
'cv::xfeatures2d::SIFT::create'
我发现的每个相关答案都建议使用 contrib 或旧版本,但这些都不再起作用。
从源代码构建它以按照错误指示恢复 SIFT 更容易,还是使用替代方案更容易?我该怎么做?我所需要的只是某种进行特征检测的方法,最好是尺度不变的。
这个问题 https://stackoverflow.com/questions/10157806/are-there-any-fast-alternatives-to-surf-and-sift-for-scale-invariant-feature-ext提到了 SIFT 替代方案,但已经非常过时了(最佳答案大约 8 年前)。 2020年我们现在能做什么?
编辑显示 OpenCV 3 不起作用:
尝试安装 OpenCV 3:
>>> pip install opencv-python==3
ERROR: Could not find a version that satisfies the requirement opencv-python==3
(from versions: 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.6.27,
3.4.7.28, 3.4.8.29, 3.4.9.31, 3.4.9.33, 4.0.0.21, 4.0.1.23, 4.0.1.24, 4.1.0.25,
4.1.1.26, 4.1.2.30, 4.2.0.32, 4.2.0.34)
ERROR: No matching distribution found for opencv-python==3
>>> pip install opencv-python==3.4.2.16
然后在Python中:
>>> import cv2
>>> print(cv2.__version__)
3.4.2
>>> cv2.SIFT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'SIFT_create'