Ask Your Question
0

How to use SIFT in python

asked 2018-09-13 10:12:10 -0500

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

berak gravatar image

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()
edit retag flag offensive close merge delete

Comments

how did you install it ?

berak gravatar imageberak ( 2018-09-13 10:35:16 -0500 )edit

I used the setting function of pycharm to add opencv-contrib-python

Bac Tran gravatar imageBac Tran ( 2018-09-13 11:43:29 -0500 )edit

btw, bug in your code: you have to use NORM_L2 for SIFT and SURF, and NORM_HAMMING for ORB,BRIEF,BISK, etc.

berak gravatar imageberak ( 2018-09-13 11:58:03 -0500 )edit

Thank you .

Bac Tran gravatar imageBac Tran ( 2018-09-13 12:13:25 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-13 12:08:01 -0500

berak gravatar image

updated 2018-09-13 12:10:15 -0500

so, the bad news is: the pip installed 3.4.3 does not have SIFT and SURF enabled. (it's NOT a problem in your code.)

while there is already an issue about it there , it will take some time mending this. (idk, what will happen there, or if even someone will convince skvark to change his mind about it)

if you really need this, you'll have to build your cv2.pyd from src, meaning you have to get:

* cmake
* vs2017 or 2015
* both opencv and opencv_contrib src from github

and follow build instructions here

you also could try to fallback to 3.4.2, which does not have this restriction.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-09-13 10:12:10 -0500

Seen: 291 times

Last updated: Sep 13