18

I know there is a lot of questions about Python and OpenCV but I didn't find help on this special topic.

I want to extract SIFT keypoints from an image in python OpenCV.

I have recently installed OpenCV 2.3 and can access to SURF and MSER but not SIFT. I can't see anything related to SIFT in python modules (cv and cv2) (well I'm lying a bit: there are 2 constants: cv2.SIFT_COMMON_PARAMS_AVERAGE_ANGLE and cv2.SIFT_COMMON_PARAMS_FIRST_ANGLE).

This puzzles me since a while. Is that related to the fact that some parts of OpenCV are in C and other in C++? Any idea?

P.S.: I have also tried pyopencv (another python binding for OpenCV <= 2.1) without success.

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
Mathieu Dubois
  • 1,054
  • 3
  • 14
  • 22
  • Did you built OpenCV from sources? – Unapiedra Jul 17 '11 at 12:23
  • Yes I have build OpenCV 2.3 from source using options CMAKE_BUILD_TYPE=RELEASE, CMAKE_INSTALL_PREFIX, BUILD_PYTHON_SUPPORT=ON,WITH_QT=ON (the compilation works without problems). – Mathieu Dubois Jul 17 '11 at 12:52
  • The guys at willowgarage put the documentation for OpenCV 2.3 online [link](http://opencv.itseez.com/). Apparently features2d in python don't include much of the stuff. – Mathieu Dubois Jul 19 '11 at 19:48

4 Answers4

6

I can't say whether this is the reason SIFT was not available via Python for OpenCV 2.3 (as the original question asks). However, the patent which was preventing SIFT from being included in OpenCV expired on 2020-03-06.

The distributed build of OpenCV now includes SIFT since version 4.4.0, accessible via cv2.SIFT_create() in Python.

See the documentation for further information on its use.

kymkcay
  • 127
  • 1
  • 8
0

You can compute SIFT features using OpenCV python bindings as follows:

  import cv2

  sift = cv2.SIFT()
  keypoints, descriptors = sift.detectAndCompute(imgray,None)
memecs
  • 7,196
  • 7
  • 34
  • 49
  • SIFT() is not working with cv2 library. i tried Python(x,y) as well, but with no success. Can u tell, from where u got the library? did u compile from source or any other method? – Prashant Shrivastava Oct 31 '14 at 04:56
0

SIFT has been patented and is not free for commercial use.

But if you want to use it for educational purposes, it's simple:

pip install opencv-python opencv-contrib-python

and then you can do

import cv2

# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()

# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img, None)
Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102
0

On ubuntu you can fix with installing this version of opencv-contrib

pip3 install opencv-contrib-python==3.4.0.12
user1941407
  • 2,722
  • 4
  • 27
  • 39