-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep5_search_image_index.py
50 lines (39 loc) · 1.3 KB
/
step5_search_image_index.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
import time
from mmkfeatures.fusion.mm_features_lib import MMFeaturesLib
from mmkfeatures.image.color_descriptor import ColorDescriptor
import numpy as np
import cv2
import pickle
from tqdm import tqdm
from mmkfeatures.image.image_searcher import Searcher
mmf_file=f"../datasets/birds_raw.mmf"
feature_lib=MMFeaturesLib(file_path=mmf_file)
data=feature_lib.get_data()
# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3))
img_path="../datasets/CUB_200_2011/images/005.Crested_Auklet/Crested_Auklet_0001_794941.jpg"
index_path="../datasets/image.index"
print("Searching....")
# load the query image and describe it
query = cv2.imread(img_path)
features = cd.describe(query)
# perform the search
start_time=time.time()
searcher = Searcher(index_path)
results = searcher.search(features)
end_time=time.time()
print("query time cost: ",end_time-start_time)
# display the query
cv2.imshow("Query", query)
cv2.waitKey(0)
# loop over the results
for (score, resultID) in results:
print(resultID,score)
image=data[str(resultID)]["objects"]["0"][()]
title=data[str(resultID)]["labels"][()][0]
cv2.imshow(str(title), image)
cv2.waitKey(0)
# load the result image and display it
# result = cv2.imread("datasets/CUB_200_2011/" + resultID)
# cv2.imshow("Result", result)
# cv2.waitKey(0)