forked from DragonFive/cv_nlp_deeplearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
38 lines (29 loc) · 1.52 KB
/
search.py
File metadata and controls
38 lines (29 loc) · 1.52 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
import colordescriptor
import structuredescriptor
import searcher
import argparse
import cv2
searchArgParser = argparse.ArgumentParser()
searchArgParser.add_argument("-c", "--colorindex", required = True, help = "Path to where the computed color index will be stored")
searchArgParser.add_argument("-s", "--structureindex", required = True, help = "Path to where the computed structure index will be stored")
searchArgParser.add_argument("-q", "--query", required = True, help = "Path to the query image")
searchArgParser.add_argument("-r", "--resultpath", required = True, help = "Path to the result path")
searchArguments = vars(searchArgParser.parse_args())
idealBins = (8, 12, 3)
idealDimension = (16, 16)
colorDescriptor = colordescriptor.ColorDescriptor(idealBins)
structureDescriptor = structuredescriptor.StructureDescriptor(idealDimension)
queryImage = cv2.imread(searchArguments["query"])
colorIndexPath = searchArguments["colorindex"]
structureIndexPath = searchArguments["structureindex"]
resultPath = searchArguments["resultpath"]
queryFeatures = colorDescriptor.describe(queryImage)
queryStructures = structureDescriptor.describe(queryImage)
imageSearcher = searcher.Searcher(colorIndexPath, structureIndexPath)
searchResults = imageSearcher.search(queryFeatures, queryStructures,5)
for imageName, score in searchResults:
queryResult = cv2.imread(resultPath + "/" + imageName)
cv2.imshow("Result Score: " + str(int(score)) + " (lower is better)", queryResult)
cv2.waitKey(0)
cv2.imshow("Query", queryImage)
cv2.waitKey(0)