spmallick / learnopencv

Learn OpenCV : C++ and Python Examples
https://www.learnopencv.com/
20.68k stars 11.52k forks source link

AttributeError: 'tuple' object has no attribute 'sort' #801

Open dacrypt opened 1 year ago

dacrypt commented 1 year ago
ImageAlignment-FeatureBased python3 align.py 
Reading reference image :  form.jpg
Reading image to align :  scanned-form.jpg
Aligning images ...
Traceback (most recent call last):
  File "align.py", line 69, in <module>
    imReg, h = alignImages(im, imReference)
  File "align.py", line 26, in alignImages
    matches.sort(key=lambda x: x.distance, reverse=False)
AttributeError: 'tuple' object has no attribute 'sort'

It is not clear what the input matches is, and how it is being passed to the alignImages() function. However, the error message suggests that matches is a tuple, and tuples do not have a sort() method.

The error message suggests that you are trying to call the sort method on a tuple object, which is not possible because tuples are immutable and do not have a sort method.

It seems that in your code, the variable matches is a tuple, and you are trying to sort it using a lambda function. To fix this error, you can convert the matches tuple to a list using the list() function, like this:

matches = list(matches)
matches.sort(key=lambda x: x.distance, reverse=False)
Alternatively, you can modify the function that returns the matches tuple to return a list instead.