Assertion failed (i2 >= 0 && i2 < static_cast(keypoints2.size())) in cv::drawMatches,
Assertion failed (i2 >= 0 && i2 < static_cast<int>(keypoints2.size())) in cv::drawMatches,
Help me if anyone know about this error? Please. I had searched it many times on google but there is no proper answer, if anyone know or face it then tell me.
**#read Keypoints
index = [line.strip() for line in open('/Users/alisa/Desktop/ali.csv')]
k =
for line in index:
list = line.split(',')
temp = cv2.KeyPoint(x=float(list[0]), y=float(list[1]), _size=float(list[2]), _angle=float(list[3]),
_response=float(list[4]), _octave=int(list[5]), _class_id=int(list[6]))
print(temp)
k.append(temp)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
print(matches)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches,None, flags=2)
plt.imshow(img3),plt.show()**
kp1
kp2
matches
matches
I have already done it with doing same length of kp1 and kp2.
– Ali110
Jun 29 at 14:03
You need to check your params you are passing, for instance I don't see where your
kp1
and kp2
are being generated, or whether img1
and img2
are even valid. Also I don't think you need to sort the matches prior to drawing them, the keypoints will have an index and these are used for matching the keypoints to each other is my understanding– EdChum
Jun 29 at 14:20
kp1
kp2
img1
img2
what kind of index that keypoints have and how to check the index??
– Ali110
Jun 29 at 14:36
I maybe confusing with
matches
, when you do a match, the matches has an index indicating the lhs and rhs index that the match has found for the corresponding keypoints, it looks like this has to be done for the python version but not in the c++ version, still the fact remains you need to check your params, also post the full error code docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/…– EdChum
Jun 29 at 14:43
matches
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
check the length of
kp1
,kp2
, andmatches
, it looks likematches
is empty– EdChum
Jun 29 at 13:32