How to use SIFT in python
I run my code this error come out : cv2.error: OpenCV(3.4.3) C:\projects\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 'cv::xfeatures2d::SIFT::create' i use opencv 3.4.3 and python 3.7 Could you tell me how to fix this error .
my code:
import numpy as np
import cv2
img1=cv2.imread("anh1.jpg")
img2=cv2.imread("anh2.jpg")
gray1=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
gray2=cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
sift=cv2.xfeatures2d.SIFT_create()
kp1,des1=sift.detectAndCompute(gray1,None)
kp2,des2=sift.detectAndCompute(gray2,None)
bf=cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches=bf.match(des1,des2)
matches=sorted(matches,key= lambda x:x.distance)
matching_result=cv2.drawMatches(img1,kp1,img2,kp2,matches[:20],None,flags=2)
cv2.imshow("image",matching_result)
cv2.waitKey(0)
cv2.destroyAllWindows()
how did you install it ?
I used the setting function of pycharm to add opencv-contrib-python
btw, bug in your code: you have to use NORM_L2 for SIFT and SURF, and NORM_HAMMING for ORB,BRIEF,BISK, etc.
Thank you .