Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIFT implementation Python error

Tags:

python

sift

I am using the SIFT implementation from vlfeat.org in Python, vlfeat.py.

I keep getting an error stating too many indices and the line number indicates that the error occurs when read_features_from_file() is executed.

I also noticed that the file features1.sift is empty, meaning something goes wrong when executing process_image().

Code Snippet :

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()

Here's what process_image looks like:

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
like image 994
user2761615 Avatar asked Aug 30 '26 16:08

user2761615


1 Answers

Try the older vlfeat version i used the binary vlfeat-0.9.21-bin.tar.gz which gave me that error. Try using the older version vlfeat-0.9.20-bin.tar.gz.

like image 77
user7703898 Avatar answered Sep 02 '26 06:09

user7703898



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!