├── vl.dll ├── vl.lib ├── sift.exe ├── tmp.pgm └── sift.py /vl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinshengwang/SIFT-Python/HEAD/vl.dll -------------------------------------------------------------------------------- /vl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinshengwang/SIFT-Python/HEAD/vl.lib -------------------------------------------------------------------------------- /sift.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinshengwang/SIFT-Python/HEAD/sift.exe -------------------------------------------------------------------------------- /tmp.pgm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinshengwang/SIFT-Python/HEAD/tmp.pgm -------------------------------------------------------------------------------- /sift.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | from numpy import * 3 | from pylab import * 4 | import os 5 | 6 | def process_image(imagename,resultname,params="--edge-thresh 10 --peak-thresh 5"): 7 | """ Process an image and save the results in a file. """ 8 | 9 | if imagename[-3:] != 'pgm': 10 | # create a pgm file 11 | im = Image.open(imagename).convert('L') #.convert('L') 将RGB图像转为灰度模式,灰度值范围[0,255] 12 | im.save('tmp.pgm') #将灰度值图像信息保存在.pgm文件中 13 | imagename = 'tmp.pgm' 14 | 15 | cmmd = str("E:\code\Sift\sift_python\sift.exe "+imagename+" --output="+resultname+ 16 | " "+params) 17 | os.system(cmmd) #执行sift可执行程序,生成resultname(test.sift)文件 18 | print 'processed', imagename, 'to', resultname 19 | 20 | 21 | def read_features_from_file(filename): 22 | """ Read feature properties and return in matrix form. """ 23 | 24 | f = loadtxt(filename) 25 | return f[:,:4],f[:,4:] # feature locations, descriptors 26 | 27 | 28 | def plot_features(im,locs,circle=True): 29 | """ Show image with features. input: im (image as array), 30 | locs (row, col, scale, orientation of each feature). """ 31 | 32 | def draw_circle(c,r): 33 | t = arange(0,1.01,.01)*2*pi 34 | x = r*cos(t) + c[0] 35 | y = r*sin(t) + c[1] 36 | plot(x,y,'b',linewidth=2) 37 | 38 | imshow(im) 39 | if circle: 40 | for p in locs: 41 | draw_circle(p[:2],p[2]) 42 | else: 43 | plot(locs[:,0],locs[:,1],'ob') 44 | axis('off') 45 | 46 | 47 | 48 | if __name__ == '__main__': 49 | imname = ('E:\\code\\Sift\\library.jpg') #待处理图像路径 50 | im=Image.open(imname) 51 | process_image(imname,'test.sift') 52 | l1,d1 = read_features_from_file('test.sift') #l1为兴趣点坐标、尺度和方位角度 l2是对应描述符的128 维向 53 | figure() 54 | gray() 55 | plot_features(im,l1,circle = True) 56 | title('sift-features') 57 | show() --------------------------------------------------------------------------------