python - 无法在 Python OpenCV v4.20 中使用 SIFT

标签 python image opencv image-processing sift

我正在使用 OpenCV v4.20 和 PyCharm IDE。我想使用SIFT算法。但我收到这个错误。我在互联网上寻找此错误的解决方案,但没有一个对我有帮助。你知道这个错误的解决方法吗? (使用 pip 我可以安装至少 3.4.2.16 版本的 OpenCV)
这是我的错误:

Traceback (most recent call last): File "C:/Users/HP/PycharmProjects/features/featuredetect.py", line 7, in sift = cv.xfeatures2d_SIFT.create()


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'


这是我的代码:
import cv2 as cv

image = cv.imread("the_book_thief.jpg")
gray_image = cv.cvtColor(image,cv.COLOR_BGR2GRAY)

sift = cv.xfeatures2d_SIFT.create()
keyPoints = sift.detect(image,None)

output = cv.drawKeypoints(image,keyPoints,None)

cv.imshow("FEATURES DETECTED",output)
cv.imshow("NORMAL",image)

cv.waitKey(0)
cv.destroyAllWindows()

最佳答案

SIFT's patent has expired在去年七月。在版本 > 4.4 中,检测器 init 命令已更改为 cv2.SIFT_create() .
如果你没有使用 opencv 的 GUI,建议安装 headless 版本:pip install opencv-python-headless

关于python - 无法在 Python OpenCV v4.20 中使用 SIFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60065707/

相关文章:

python - 在python中检测像素化图像

image - docker ,无效的引用格式

Java openCV - 使用 Imgproc.matchTemplate 方法后,如何检查结果?

python - 列出对opencv bgr的理解,以对调色板进行十六进制合并。 TypeError:无法解压缩不可迭代的numpy.uint8对象

python - tkinter 对 child 的点击不会传播给 parent

python - django v1.10 mysite.com 的 urls.py 条目 :8000/index. html

html - 如何使此图像位于文本下方?

arrays - cv.fillPoly生成零数组,不读取输入

python - 使用 PGP 通过 Python 解密存储在 SFTP 服务器上的文件

python - 如何在 Python 中使用 google.auth 而不是 oauth2client 来访问我的 Google 日历