-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectorise.py
More file actions
72 lines (51 loc) · 1.99 KB
/
Copy pathvectorise.py
File metadata and controls
72 lines (51 loc) · 1.99 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse
import os
import sys
import cv2
import numpy as np
from util import load_coordinates, load_images
def build_features(images, filename, bins=16):
descfile = filename + '_desc'
targfile = filename + '_targ'
# histfile = filename + '_hist'
if os.path.isfile(descfile) or os.path.isfile(targfile):
sys.exit('filename in use: {}'.format(filename))
# hist = np.empty(3 * bins * len(images), dtype=np.int32)
sift = cv2.xfeatures2d.SIFT_create()
desc = []
targ = np.zeros(len(images), dtype=np.uint32)
# idx = 0
for i, img in enumerate(images):
image = cv2.imread(img, cv2.IMREAD_GRAYSCALE)
kp, des = sift.detectAndCompute(image, None)
# for c in range(3):
# hist = cv2.calcHist([image], [c], None, [bins], [0, 256])[:,0]
# hists[idx:idx+bins] = hist
# idx += bins
# TODO: very-large scale; look at prefix-sum trees
# targ.extend([i] * len(des))
targ[i] = targ[i - 1] + len(kp)
desc.extend(des.astype(np.uint8))
if i % 100 == 0:
print('images processed: {}'.format(i))
# with open(histfile, "wb") as fd:
# np.save(fd, hists)
with open(descfile, "wb") as fd:
np.save(fd, np.asarray(desc))
with open(targfile, "wb") as fd:
np.save(fd, targ)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('coordinates', type=str, help='image-coordinate map')
parser.add_argument('images', type=str, help='Street View image directory')
parser.add_argument('outfile', type=str, help='computed feature output')
args = parser.parse_args()
coordinates = load_coordinates(args.coordinates)
images = load_images(args.images)
# Perform a length-check to enforce consistency
if len(images) % len(coordinates) != 0:
sys.exit('image-coordinate map not consistent')
# Use a SIFT feature extractor
build_features(images, args.outfile)
if __name__ == "__main__":
main()