-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
55 lines (34 loc) · 1.21 KB
/
search.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
52
53
54
55
from pyimagesearch.colordescriptor import ColorDescriptor
from pyimagesearch.searcher import Searcher
import argparse
import cv2
from imutils import build_montages
from imutils import paths
import random
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--index", required = True,
help = "Path to where the computed index will be stored")
ap.add_argument("-q", "--query", required = True,
help = "Path to the query image")
ap.add_argument("-r", "--result-path", required = True,
help = "Path to the result path")
ap.add_argument("-s", "--sample", type=int, default=21,
help="# of images to sample")
args = vars(ap.parse_args())
imagePaths = list(paths.list_images(args["result_path"]))
random.shuffle(imagePaths)
imagePaths = imagePaths[:args["sample"]]
cd = ColorDescriptor((8, 12, 3))
query = cv2.imread(args["query"])
features = cd.describe(query)
searcher = Searcher(args["index"])
results = searcher.search(features)
cv2.imshow("Query", query)
images = []
for (score,resultID) in results:
result = cv2.imread(args["result_path"] + "/" + resultID)
images.append(result)
montages = build_montages(images, (128, 196), (3, 6))
for montage in montages:
cv2.imshow("Search Results", montage)
cv2.waitKey(0)