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
from PCV.imagesearch import imagesearch from PCV.localdescriptors import sift import sqlite3 from PCV.tools.imtools import get_imlist #获取图像列表 imlist = get_imlist('training/') nbr_images = len(imlist) #获取特征列表 featlist = [imlist[i][:-3] + 'sift' for i in range(nbr_images)] # load vocabulary with open('training/vocabulary.pkl', 'rb') as f: voc = pickle.load(f) # 创建索引 indx = imagesearch.Indexer('testImaAdd_training.db', voc) indx.create_tables() # go through all images, project features on vocabulary and insert for i in range(nbr_images): locs, descr = sift.read_features_from_file(featlist[i]) indx.add_to_index(imlist[i], descr) # commit to database indx.db_commit() con = sqlite3.connect('testImaAdd_training.db') print(con.execute('select count (filename) from imlist').fetchone()) print(con.execute('select * from imlist').fetchone())
import pickle from PCV.imagesearch import imagesearch from PCV.localdescriptors import sift from sqlite3 import dbapi2 as sqlite from PCV.tools.imtools import get_imlist imlist = get_imlist('./first500/') nbr_images = len(imlist) featlist = [imlist[i][:-3] + 'sift' for i in range(nbr_images)] # load vocabulary with open('./first500/vocabulary.pkl', 'rb') as f: voc = pickle.load(f) # create indexer indx = imagesearch.Indexer('web.db', voc) indx.create_tables() # go through all images, project features on vocabulary and insert for i in range(nbr_images)[:500]: locs, descr = sift.read_features_from_file(featlist[i]) indx.add_to_index(imlist[i], descr) # commit to database indx.db_commit() con = sqlite.connect('web.db') print con.execute('select count (filename) from imlist').fetchone() print con.execute('select * from imlist').fetchone()
import pickle from PCV.imagesearch import imagesearch from PCV.localdescriptors import sift from sqlite3 import dbapi2 as sqlite from PCV.tools.imtools import get_imlist import os path = "F:\\BaiduNet\\ukbench\\full\\" imlist = [os.path.join(path, f) for f in os.listdir(path)] imnbr = len(imlist) featlist = [imlist[i].split('\\')[-1][:-3] + 'sift' for i in range(imnbr)] with open('vocabulary.pkl', 'rb') as f: voc = pickle.load(f) index = imagesearch.Indexer('testImgAdd.db', voc) index.create_tables() for i in range(imnbr)[:500]: locs, descr = sift.read_features_from_file(featlist[i]) index.add_to_index(imlist[i], descr) index.db_commit() con = sqlite.connect('testImgAdd.db') print con.execute('select * from imlist').fetchone()