OpenCV Python and SIFT features

自古美人都是妖i 提交于 2019-12-03 15:33:26

问题


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.


回答1:


Are you sure OpenCV is allowed to support SIFT? SIFT is a proprietary feature type, patented within the U.S. by the University of British Columbia and by David Lowe, the inventor of the algorithm. In my own research, I have had to re-write this algorithm many times. In fact, some vision researchers try to avoid SIFT and use other scale-invariant models because SIFT is proprietary.




回答2:


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

  import cv2

  sift = cv2.SIFT()
  keypoints, descriptors = sift.detectAndCompute(imgray,None)



回答3:


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)



回答4:


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

pip3 install opencv-contrib-python==3.4.0.12


来源:https://stackoverflow.com/questions/6722736/opencv-python-and-sift-features

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!