问题描述
我正在使用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)
这是我的错误:
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.2 中不再可用.由于您使用的是OpenCV v4.2.0,因此即使您已安装pip install opencv-contrib-python
,它也不包含在其中,如.解决方法是将其降级到任何包含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
这篇关于无法在OpenCV v4.20中使用SIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!