Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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()

click to hide/show revision 2
None

updated 2018-09-13 11:56:15 -0600

berak gravatar image

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()

cv2.destroyAllWindows()