-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathindexBallTree.py
52 lines (40 loc) · 1.39 KB
/
indexBallTree.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
50
51
# Jorge Guevara
# compute ball tree data from the VLAD descriptors
# USAGE :
# python indexBallTree.py -d VLADdescriptorPath -l leafSize -o output
# example :
# python indexBallTree.py -d VLADdescriptors/VLAD_SURF_W16.pickle -l 20 -o ballTreeIndexes/index_SURF_W16
from VLADlib.VLAD import *
from VLADlib.Descriptors import *
import pickle
import argparse
import glob
import cv2
#parser
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--VLADdescriptorPath", required = True,
help = "Path to the file that contains the VLAD descriptors")
ap.add_argument("-l", "--leafSize", required = True,
help = "Size of the leafs of the Ball tree")
ap.add_argument("-o", "--output", required = True,
help = "Path to where VLAD descriptors will be stored")
args = vars(ap.parse_args())
#args
path = args["VLADdescriptorPath"]
leafSize = int(args["leafSize"])
output=args["output"]
#estimating VLAD descriptors for the whole dataset
print("indexing VLAD descriptors from "+path+ " with a ball tree:")
#load the vlad descriptors VD=[imageID, VLADdescriptors, pathToImageDataSet]
with open(path, 'rb') as f:
VLAD_DS=pickle.load(f)
imageID=VLAD_DS[0]
V=VLAD_DS[1]
pathImageData=VLAD_DS[2]
tree = indexBallTree(V,leafSize)
#output
file=output+".pickle"
with open(file, 'wb') as f:
pickle.dump([imageID,tree,pathImageData], f,pickle.HIGHEST_PROTOCOL)
print("The ball tree index is saved at "+file)