Ask Your Question

MattMgn's profile - activity

2018-02-13 15:32:45 -0600 commented answer [BFMatcher] 'list' object has no attribute 'trainIdx'

Allright, I understand ! Thank you eshirima matt

2018-02-13 15:31:31 -0600 marked best answer [BFMatcher] 'list' object has no attribute 'trainIdx'

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

2018-02-13 15:31:31 -0600 received badge  Scholar (source)
2018-02-08 12:30:15 -0600 asked a question Can't get attribute trainIdx from BFMatcher

Can't get attribute trainIdx from BFMatcher Hello I am trying to get attributes from Matcher object. Even if I can succ

2018-02-08 12:30:15 -0600 asked a question [BFMatcher] 'list' object has no attribute 'trainIdx'

[BFMatcher] 'list' object has no attribute 'trainIdx' Hello I am trying to get attributes from Matcher object. Even if