0

我将关键点和描述符保存在 JSON 文件中。后来当我检索它们时,我试图在FlannBasedMatcher. 但是,我认为转换中出了点问题,因为我收到了以下错误。

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
4

1 回答 1

0

解决方案看似简单。

des2 = np.array(rawDes,dtype=np.uint8)
于 2019-05-26T03:01:09.660 回答