Ejemplo n.º 1
0
def add(file):

    targetImgSiftPath = file[:-3] + 'sift'
    sift.process_image(file, targetImgSiftPath)


    voc = vocabulary.Vocabulary('target')
    voc.train([targetImgSiftPath], 100, 10)
    print('vocabulary is:', voc.name, voc.nbr_words)
    locs, descr = sift.read_features_from_file(targetImgSiftPath)


    indx = imagesearch.Indexer('testImaAdd.db', voc)
    indx.add_to_index(file, descr)
    indx.db_commit()

    return voc
# -*- coding: utf-8 -*-
import pickle
from PCV.imagesearch import vocabulary
from PCV.tools.imtools import get_imlist
from PCV.localdescriptors import sift

#获取图像列表
imlist = get_imlist('./first500/')
nbr_images = len(imlist)
#获取特征列表
featlist = [imlist[i][:-3] + 'sift' for i in range(nbr_images)]

#提取文件夹下图像的sift特征
for i in range(nbr_images):
    sift.process_image(imlist[i], featlist[i])

#生成词汇
voc = vocabulary.Vocabulary('ukbenchtest')
voc.train(featlist, 1000, 10)
#保存词汇
# saving vocabulary
with open('./first500/vocabulary.pkl', 'wb') as f:
    pickle.dump(voc, f)
print('vocabulary is:', voc.name, voc.nbr_words)
# -*- coding: utf-8 -*-
import pickle
from PCV.imagesearch import vocabulary
from PCV.tools.imtools import get_imlist
from PCV.localdescriptors import sift

imlist = get_imlist('./first500/')
nbr_images = len(imlist)
featlist = [imlist[i][:-3]+'sift' for i in range(nbr_images)]

for i in range(nbr_images):
    sift.process_image(imlist[i], featlist[i])

voc = vocabulary.Vocabulary('ukbench')
voc.train(featlist, 1000, 10)
# saving vocabulary
with open('./first500/vocabulary.pkl', 'wb') as f:
    pickle.dump(voc, f)
print 'vocabulary is:', voc.name, voc.nbr_words
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
import pickle
from PCV.imagesearch import vocabulary
from PCV.tools.imtools import get_imlist
import sift

# 该文件生成训练集的词汇 并将结果保存在pkl

#获取图像列表
imlist = get_imlist('training/')
nbr_images = len(imlist)

#获取特征列表
featlist = [imlist[i][:-3] + 'sift' for i in range(nbr_images)]

#提取文件夹下图像的sift特征
# for i in range(nbr_images):
#     sift.process_image(imlist[i], featlist[i])

#生成词汇
voc = vocabulary.Vocabulary('training')
voc.train(featlist, 100, 10)

# saving vocabulary
with open('training/vocabulary.pkl', 'wb') as f:
    pickle.dump(voc, f)
print('vocabulary is:', voc.name, voc.nbr_words)