无法在Python OpenCV v4.20中使用SIFT [英] Can't use SIFT in Python OpenCV v4.20

查看:552
本文介绍了无法在Python OpenCV v4.20中使用SIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using OpenCV v4.20 and PyCharm IDE. I want to use SIFT algorithm. But I get this error. I looked for solutions of this error on the internet but none of them did help me. Do you know the solution of this error? (With pip I can install at least 3.4.2.16 version of OpenCV)

这是我的错误:

回溯(最近通话最近): 文件"C:/Users/HP/PycharmProjects/features/featuredetect.py",第7行, sift = cv.xfeatures2d_SIFT.create()

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:错误:(-213:未实现功能/功能)此算法已申请专利,并且在此配置中不包括在内;设置OPENCV_ENABLE_NONFREE CMake选项并在函数'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()

推荐答案

不幸的是,根据这个Github问题,此帖子.解决方法是将其降级到任何包含SIFT的先前OpenCV版本(我相信3.4.3以下的任何版本).降级为v3.4.2.16时,我已经成功.

Unfortunately, according to this Github issue, SIFT no longer available in opencv > 3.4.2. Since you're using OpenCV v4.2.0, it's not included even if you have installed pip install opencv-contrib-python as shown in this post. A work around is to downgrade to any previous OpenCV version that includes SIFT (I believe any version below 3.4.3). I've been successful when downgrading to v3.4.2.16.

pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16


将代码与v3.4.2.16一起使用,SIFT似乎可以正常工作


Using your code with v3.4.2.16, SIFT seems to work

这篇关于无法在Python OpenCV v4.20中使用SIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆