Example #1
0
    def index(self, query=None):
        self.src = imagesearch.Searcher('testImaAdd.db', self.voc)

        html = self.header
        html += """
            <br />
            Click an image to search. <a href='?query='> Random selection </a> of images.
            <br /><br />
            """
        if query:
            # query the database and get top images
            #查询数据库,并获取前面的图像
            res = self.src.query(query)[:self.maxres]
            for dist, ndx in res:
                imname = self.src.get_filename(ndx)
                html += "<a href='?query="+imname+"'>"
                
                html += "<img src='"+imname+"' alt='"+imname+"' width='100' height='100'/>"
                print (imname+"################")
                html += "</a>"
            # show random selection if no query
            # 如果没有查询图像则随机显示一些图像
        else:
            random.shuffle(self.ndx)
            for i in self.ndx[:self.maxres]:
                imname = self.imlist[i]
                html += "<a href='?query="+imname+"'>"
                
                html += "<img src='"+imname+"' alt='"+imname+"' width='100' height='100'/>"
                print (imname+"################")
                html += "</a>"

        html += self.footer
        return html
Example #2
0
    def index(self, query=None):
        self.src = imagesearch.Searcher('web.db', self.voc)

        html = self.header
        html += """
            <br />
            Click an image to search. <a href='?query='> Random selection </a> of images.
            <br /><br />
            """
        if query:
            # query the database and get top images
            res = self.src.query(query)[:self.maxres]
            for dist, ndx in res:
                imname = self.src.get_filename(ndx)
                html += "<a href='?query=" + imname + "'>"
                html += "<img src='" + imname + "' width='100' />"
                html += "</a>"
        else:
            # show random selection if no query
            random.shuffle(self.ndx)
            for i in self.ndx[:self.maxres]:
                imname = self.imlist[i]
                html += "<a href='?query=" + imname + "'>"
                html += "<img src='" + imname + "' width='100' />"
                html += "</a>"

        html += self.footer
        return html
def get(voc, imname):

    # 显示搜索返回的图像数
    maxres = 25

    # 载入词汇
    src = imagesearch.Searcher('testImaAdd.db', voc)

    # 查询数据库,并获取前面的图像
    res = src.query(imname)[:maxres]
    list = []
    for dist, ndx in res:
        list.append(src.get_filename(ndx))

    return list
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)]

# 载入词汇
f = open('./first500/vocabulary.pkl', 'rb')
voc = pickle.load(f)
f.close()

src = imagesearch.Searcher('testImaAdd.db', voc)
locs, descr = sift.read_features_from_file(featlist[0])
iw = voc.project(descr)

print('ask using a histogram...')
print(src.candidates_from_histogram(iw)[:10])

src = imagesearch.Searcher('testImaAdd.db', voc)
print('try a query...')

nbr_results = 12
res = [w[1] for w in src.query(imlist[0])[:nbr_results]]
imagesearch.plot_results(src, res)
Example #5
0
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)]

f = open('./first500/vocabulary.pkl', 'rb')
voc = pickle.load(f)
f.close()

src = imagesearch.Searcher('web.db', voc)
locs, descr = sift.read_features_from_file(featlist[0])
iw = voc.project(descr)

print 'ask using a histogram...'
print src.candidates_from_histogram(iw)[:10]

src = imagesearch.Searcher('web.db', voc)
print 'try a query...'

nbr_results = 12
res = [w[1] for w in src.query(imlist[39])[:nbr_results]]
imagesearch.plot_results(src, res)