简体   繁体   中英

SIFT using Python 3.4

I am using Python 3.4 with naconda 2.3.0 to try the SIFT in MacOS, but there is always command not found when executing my code. Vlfeat 0.9.20 sift and the lib files are included but no idea what's wrong. My code is as below:

from PIL import Image
from numpy import *
from pylab import *
import os

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)   

and the error from the compiler is:

sh: sifttmp.pgm--output=IMG0232.sift--edge-thresh: command not found

it cannot transfer to feature file and breaks down

I have consulted from the internet and tried some modifications but it still does not work. Is there any other transformation from Python2.X to 3.X? Thanks

The SIFT comand line tool is as far as I can see called sift . But due to faulty string operations, the final command does not include the required spaces, and is thus instead sifttmp.pgm--output=IMG0232.sift--edge-thresh , which obviously does not exist.

Replace

cmmd = str("sift" + imagename + "--output=" + resultname+ "" +params)

with

 cmmd = "sift {} --output={} {}".format(imagename, resultname, params)

The above is cleaner to read, and will contain the spaces missing in your current code. It might be that the sift executable is not on the path, and then you might have to give it the full (absolute) path. Eg if you have sift in the directory /User/foo/Applications/ :

 cmmd = "/User/foo/Applications/sift {} --output={} {}".format(imagename, resultname, params)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM