Ask Your Question
0

How to use SIFT in python

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

Bac Tran gravatar image

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

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 -0600 )edit

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

Bac Tran gravatar imageBac Tran ( 2018-09-13 11:43:29 -0600 )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 -0600 )edit

Thank you .

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

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-03-18 15:13:01 -0600

i tried to make a guide how to build openCV 4.1.0 with python3.6 -

http://pravo-u.ru/blog/%d1%81%d0%b1%d...

SURF and SIFT work!

edit flag offensive delete link more

Comments

Hi @zoldaten, I had the same problem and I followed the steps you wrote to build OpenCV, all done. In C:\Program Files (x86)\Python37-32\Lib\site-packages\~v2 there is a cv2.cp37-win32.pyd file. I am just a little bit confused about the last step, which files do I need to copy where? Can you help me with that? My built Opencv is here: D:\OpenCV\opencvbuild I have Windows7.

Gergo gravatar imageGergo ( 2019-04-13 05:25:29 -0600 )edit
0

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

berak gravatar image

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

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

Question Tools

1 follower

Stats

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

Seen: 28,102 times

Last updated: Sep 13 '18