Hello
I am trying to get attributes from Matcher object.
Even if I can successfully get distance
attributes, I can't get trainIdx
one.
print(matches.trainIdx[:10]) AttributeError: 'list' object has no attribute 'trainIdx'
As it would be possible, as define here:
The result of matches = bf.match(des1,des2) line is a list of DMatch objects. This DMatch object has following attributes:
- DMatch.distance - Distance between descriptors. The lower, the better it is.
- DMatch.trainIdx - Index of the descriptor in train descriptors
- DMatch.queryIdx - Index of the descriptor in query descriptors
- DMatch.imgIdx - Index of the train image.
Code I use is:
imgL = cv2.imread('im0.png')
grayL = cv2.cvtColor(imgL, cv2.COLOR_BGR2GRAY)
imgR = cv2.imread('im1.png')
grayR = cv2.cvtColor(imgR, cv2.COLOR_BGR2GRAY)
# Initiate SIFT DETECTOR
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kpL, desL = sift.detectAndCompute(grayL, None)
kpR, desR = sift.detectAndCompute(grayR, None)
print("# kp: {}, descriptors: {}".format(len(kpL), desL.shape))
# create BFMatcher object
bf = cv2.BFMatcher()
# Match descriptors.
matches = bf.match(desL,desR)
print(matches.trainIdx[:10])
matt