我正在使用vlfeat.org提供的Python SIFT实现,即vlfeat.py。
我一直收到一个错误,指出索引太多,而行号表明当执行read_features_from_file()
时发生了错误。
我还注意到文件features1.sift是空的,这意味着在执行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