我在 Python 中使用 vlfeat.org 的 SIFT 实现,vlfeat.py。
我不断收到一个错误,指出索引过多,并且行号表示read_features_from_file()
执行时发生错误。
我还注意到文件features1.sift是空的,这意味着当executing process_image()
.
代码片段:
from PIL import Image
from pylab import *
import vlfeat as vlf
vlf.process_image('semper1.jpg','features1.sift', params="--edge-thresh 10 --peak-thresh 5")
l1,d1 = vlf.read_features_from_file('features1.sift')
image = array(Image.open('semper1.jpg'))
vlf.process_image('semper2.jpg','features2.sift', params="--edge-thresh 10 --peak-thresh 5")
l2,d2 = vlf.read_features_from_file('feautures2.sift')
image2 = array(Image.open('semper2.jpg'))
matches = vlf.match(d1,d2)
imshow(image)
for k in xrange(len(matches)):
if matches[k] > 0:
plot(l1[k, 0], l1[k, 1], 'r.')
plot([l1[k,0], l2[matches[k,0],0]], [l1[k,1], l2[matches[k,0],1]], 'b-')
show()
这是 process_image 的样子:
def process_image(imagename,resultname,params="--edge-thresh 10 --peak-thresh 5"):
""" process an image and save the results in a file"""
if imagename[-3:] != 'pgm':
#create a pgm file
im = Image.open(imagename).convert('L')
im.save('tmp.pgm')
imagename = 'tmp.pgm'
cmmd = str("sift "+imagename+" --output="+resultname+ " "+params)
os.system(cmmd)
print 'processed', imagename, 'to', resultname