learnopencv icon indicating copy to clipboard operation
learnopencv copied to clipboard

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

Open dacrypt opened this issue 1 year ago • 0 comments

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.

dacrypt avatar Feb 20 '23 06:02 dacrypt