在我的项目中,我将为服务器提供图像,并且服务器必须在数据集中搜索相似的图像。
我正在使用基于orb和Flann的Matcher在查询图像和数据集中的每个图像之间找到匹配项。 这是我的searcher.py文件,根据匹配项,该文件仍然缺少一些代码:
# import the necessary packages
from orbdescriptor import orbdescriptor
from orb_pickle import orb_pickle
import argparse
import glob
import cv2
import pickle
import numpy as np
class Searcher:
def __init__(self, indexPath):
# store our index path
self.indexPath = indexPath
def search(self, kp, desc, limit = 10):
# initialize our dictionary of results
results = {}
FLANN_INDEX_LSH = 0
MIN_MATCH_COUNT = 10
orbpickle = orb_pickle()
index_params = dict(algorithm = FLANN_INDEX_LSH, table_number = 12, key_size = 20, multi_probe_level = 2)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv2.FlannBasedMatcher(index_params,search_params)
# open the index file for reading
keypoints_database = pickle.load( open( "keypoints_database.p", "rb" ) )
for keypoint_item in keypoints_database:
kp1, desc1, image_path = orbpickle.unpickle_keypoints(keypoint_item)
if (len(desc1) > 0):
desc = np.float32(desc)
desc1 = np.float32(desc1)
matches = flann.knnMatch(desc,desc1,k=2)
问题是,根据上面代码中搜索到的匹配项,我还能怎么做才能在数据集中找到相似的图像? 任何帮助将不胜感激...