scale invariant feature transform (sift)
图像尺度空间
在一定的范围内,无论物体是大还是小,人眼都可以分辨出来,然而计算机要有相同的能力却很难,所以要让机器能够对物体在不同尺度下有一个统一的认知, 就需要考虑图像在不同的尺度下都存在的特点

lena.jpg
python
import cv2
import numpy as np
img = cv2.imread('lena.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
另外,需要查一下自己OpenCV的版本号,如果过低或者最新的都是可以用相关函数的。
python
cv2.__version__
这里可以输出自己的版本号
得到特征点
python
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(gray,None)
python
img = cv2.drawKeypoints(gray,kp,img)
cv2.imshow('drawKeypoints',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
输出结果:

计算特征
python
kp,des = sift.compute(gray,kp)
python
print (np.array(kp).shape)
输出结果:
(319,)
python
des.shape
输出结果:
python
(319, 128)
python
des[0]
输出结果:
