转换关键点与JSON之间的转换,然后使用FlannBasedMatcher进行转换 [英] Issue converting KeyPoints to and from JSON and then using FlannBasedMatcher
本文介绍了转换关键点与JSON之间的转换,然后使用FlannBasedMatcher进行转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将关键点和描述符保存在JSON文件中.稍后,当我检索它们时,我试图在FlannBasedMatcher
中使用它们.但是,我认为转换中出现了问题,因为我遇到了以下错误.
I'm saving my KeyPoints and Descriptors in a JSON file. Later when I retrieve them, I am trying to use them in a FlannBasedMatcher
. However, I think something is going wrong in the conversion because I am getting the following error.
cv2.error: OpenCV(4.1.0) /io/opencv/modules/flann/src/miniflann.cpp:315: error: (-210:Unsupported format or combination of formats) in function 'buildIndex_'
> type=4
>
创建关键点和描述符
brisk = cv2.BRISK_create()
kp1, des1 = brisk.detectAndCompute(img, None)
转换为JSON
temp = [{'point0':k.pt[0],'point1':k.pt[1],'size':k.size,'angle': k.angle, 'response': k.response, "octave":k.octave,
"id":k.class_id} for k in kp1]
json.dumps(temp) #JSON KeyPoints
json.dumps(des1.tolist()) #JSON Descriptors
向后转换
rawKeys = json.loads(result[key]["KEYPOINTS"])
rawDes = json.loads(result[key]["DESCRIPTORS"])
kp2 = []
for kp in rawKeys:
p = cv2.KeyPoint(x=kp["point0"],y=kp["point0"],_size=kp["size"], _angle=kp["angle"], _response=kp["response"], _octave=kp["octave"], _class_id=kp["id"])
kp2.append(p)
des2 = np.array(rawDes)
匹配器
FLANN_INDEX_LSH = 6
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
search_params = dict(checks = 50)
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(des1,des2,k=2) # ERROR HERE
推荐答案
解决方案看似简单.
des2 = np.array(rawDes,dtype=np.uint8)
这篇关于转换关键点与JSON之间的转换,然后使用FlannBasedMatcher进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文