-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathch07_query.py
35 lines (25 loc) · 909 Bytes
/
ch07_query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cPickle as pickle
import imtools
import sift
import imagesearch
"""After ch07_buildindex.py has built an index in test.db, this program can
query it.
"""
imlist = imtools.get_imlist('/Users/thakis/Downloads/ukbench/first1000')[:100]
imcount = len(imlist)
featlist = [imlist[i][:-3] + 'sift' for i in range(imcount)]
with open('vocabulary.pkl', 'rb') as f:
voc = pickle.load(f)
searcher = imagesearch.Searcher('test.db', voc)
locs, descr = sift.read_features_from_file(featlist[0])
imwords = voc.project(descr)
print 'ask using a histogram...'
print searcher.candidates_from_histogram(imwords)[:10]
print 'try a query...'
res = searcher.query(imlist[0])[:10]
print res
print 'score:'
# Score a small subset, so this runs fast.
print imagesearch.compute_ukbench_score(searcher, imlist[:10])
# Plot images most similar to imlist[0].
imagesearch.plot_results(searcher, [r[1] for r in res[:6]])