Issue converting KeyPoints to and from JSON and then using FlannBasedMatcher

旧街凉风 提交于 2019-12-11 19:11:38

问题


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
> 

Creating the keypoints and descriptors

brisk = cv2.BRISK_create()
kp1, des1 = brisk.detectAndCompute(img, None)

Converting to 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

Converting back

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)

Matcher

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

回答1:


Solution was deceptively simple.

des2 = np.array(rawDes,dtype=np.uint8)


来源:https://stackoverflow.com/questions/56271253/issue-converting-keypoints-to-and-from-json-and-then-using-flannbasedmatcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!