資源簡(jiǎn)介
具體使用,請(qǐng)參看博文10,里面有詳細(xì)的使用介紹。
代碼片段和文件信息
from?PIL?import?Image
from?numpy?import?*
from?pylab?import?*
import?os
def?process_image(imagenameresultnameparams=“--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(“E:\Python-PCV\VLFeat\win64\sift.exe?“+imagename+“?--output=“+resultname+
????????????????“?“+params)
????os.system(cmmd)
????print?‘processed‘?imagename?‘to‘?resultname
def?read_features_from_file(filename):
????“““?Read?feature?properties?and?return?in?matrix?form.?“““
????
????f?=?loadtxt(filename)
????return?f[::4]f[:4:]?#?feature?locations?descriptors
def?write_features_to_file(filenamelocsdesc):
????“““?Save?feature?location?and?descriptor?to?file.?“““
????savetxt(filenamehstack((locsdesc)))
????
def?plot_features(imlocscircle=False):
????“““?Show?image?with?features.?input:?im?(image?as?array)?
????????locs?(row?col?scale?orientation?of?each?feature).?“““
????def?draw_circle(cr):
????????t?=?arange(01.01.01)*2*pi
????????x?=?r*cos(t)?+?c[0]
????????y?=?r*sin(t)?+?c[1]
????????plot(xy‘b‘linewidth=2)
????imshow(im)
????if?circle:
????????for?p?in?locs:
????????????draw_circle(p[:2]p[2])?
????else:
????????plot(locs[:0]locs[:1]‘ob‘)
????axis(‘off‘)
def?match(desc1desc2):
????“““?For?each?descriptor?in?the?first?image?
????????select?its?match?in?the?second?image.
????????input:?desc1?(descriptors?for?the?first?image)?
????????desc2?(same?for?second?image).?“““
????
????desc1?=?array([d/linalg.norm(d)?for?d?in?desc1])
????desc2?=?array([d/linalg.norm(d)?for?d?in?desc2])
????
????dist_ratio?=?0.6
????desc1_size?=?desc1.shape
????
????matchscores?=?zeros((desc1_size[0])‘int‘)
????desc2t?=?desc2.T?#?precompute?matrix?transpose
????for?i?in?range(desc1_size[0]):
????????dotprods?=?dot(desc1[i:]desc2t)?#?vector
評(píng)論
共有 條評(píng)論