-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.py
executable file
·50 lines (40 loc) · 1.49 KB
/
generate.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import argparse
from cPickle import load
from learn import extractSift, computeHistograms, writeHistogramsToFile
HISTOGRAMS_FILE = 'visual_words_for_test_data'
CODEBOOK_FILE = 'codebook_b.file'
IMAGE_INDEX_FILE = 'image_indexe_test'
def parse_arguments():
parser = argparse.ArgumentParser(description='generate visual words histogram for test image')
parser.add_argument('-c', help='path to the codebook file', required=False, default=CODEBOOK_FILE)
parser.add_argument('input_image', help='path to input image', nargs='+')
args = parser.parse_args()
return args
print "---------------------"
print "## extract Sift features"
all_files = []
all_features = {}
args = parse_arguments()
codebook_file = args.c
fnames = args.input_image
all_features = extractSift(fnames)
print "---------------------"
print "## loading codebook from " + codebook_file
with open(codebook_file, 'rb') as f:
codebook = load(f)
print "---------------------"
print "## computing visual word histograms"
all_word_histgrams = {}
for imagefname in all_features:
word_histgram = computeHistograms(codebook, all_features[imagefname])
all_word_histgrams[imagefname] = word_histgram
print "---------------------"
print "## write the histograms to file"
nclusters = codebook.shape[0]
writeHistogramsToFile(nclusters,
fnames,
all_word_histgrams,
IMAGE_INDEX_FILE,
HISTOGRAMS_FILE)
print "---------------------"
print "finished"