Fix find_obj sample when image descriptors are unavailable 🤖🤖🤖 (#30812)

Keep the feature-matching samples find_obj.py and asift.py usable when the second image has no feature descriptors.

find_obj.py receives None and asift.py receives an empty NumPy array in this case. Both samples skip knnMatch() and continue through the existing zero-match visualization.
This commit is contained in:
Ahmet Mert Özacar
2026-12-02 12:31:42 +03:00
committed by GitHub
parent 4cab9c8fa5
commit 8251b372fe
2 changed files with 2 additions and 2 deletions

View File

@@ -143,7 +143,7 @@ def main():
def match_and_draw(win):
with Timer('matching'):
raw_matches = matcher.knnMatch(desc1, trainDescriptors = desc2, k = 2) #2
raw_matches = matcher.knnMatch(desc1, trainDescriptors=desc2, k=2) if desc2.size else []
p1, p2, kp_pairs = filter_matches(kp1, kp2, raw_matches)
if len(p1) >= 4:
H, status = cv.findHomography(p1, p2, cv.RANSAC, 5.0)

View File

@@ -174,7 +174,7 @@ def main():
def match_and_draw(win):
print('matching...')
raw_matches = matcher.knnMatch(desc1, trainDescriptors = desc2, k = 2) #2
raw_matches = matcher.knnMatch(desc1, trainDescriptors=desc2, k=2) if desc2 is not None else []
p1, p2, kp_pairs = filter_matches(kp1, kp2, raw_matches)
if len(p1) >= 4:
H, status = cv.findHomography(p1, p2, cv.RANSAC, 5.0)