Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open CV
#1
Lightbulb 
Hi all,

This post is regarding image registration using open CV. I have come across this article in Geeks for geeks and following is the link:

https://www.geeksforgeeks.org/image-regi...cv-python/

I have tried the same code mentioned in the site and was getting the following error:

Traceback (most recent call last):
File "F:/images2/align_01.py", line 31, in <module>
matches.sort(key = lambda x: x.distance)
AttributeError: 'tuple' object has no attribute 'sort'[/color]

After changing the line to :
matches = tuple(sorted(key = lambda x: x.distance))

Error has changed to:
Traceback (most recent call last):
File "F:/images2/align_01.py", line 32, in <module>
matches = tuple(sorted(key = lambda x: x.distance))
TypeError: sorted expected 1 argument, got 0

can anyone help me in correcting the error?

Thanks & Regards,
Utkarsha.
Reply
#2
maybe

matches = tuple(sorted(key = x.distance))
Reply
#3
(Feb-25-2022, 05:47 AM)Utkarsha Wrote: matches.sort(key = lambda x: x.distance)
AttributeError: 'tuple' object has no attribute 'sort'[/color]
Without knowing anything about the program I understand "matches" is a tuple. Ik makes sense a tuple cannot be sorted because it is immutable. So you did well replacing "sort()" with sorted(). But then you must tell this function what to sort: the original tuple. So I guess it has to be:
matches = tuple(sorted(matches, key=lambda x: x.distance))
( @Axel_Erfurt : the key argument must be a function expecting one argument: the record.)
Reply
#4
(Feb-25-2022, 10:22 AM)ibreeden Wrote:
(Feb-25-2022, 05:47 AM)Utkarsha Wrote: matches.sort(key = lambda x: x.distance)
AttributeError: 'tuple' object has no attribute 'sort'[/color]
Without knowing anything about the program I understand "matches" is a tuple. Ik makes sense a tuple cannot be sorted because it is immutable. So you did well replacing "sort()" with sorted(). But then you must tell this function what to sort: the original tuple. So I guess it has to be:
matches = tuple(sorted(matches, key=lambda x: x.distance))
( @Axel_Erfurt : the key argument must be a function expecting one argument: the record.)

Thank you @Axel_Erfurt & @ibreeden for timely reply.

As suggested, I have tried using
matches = tuple(sorted(key = lambda x:x.distance))

Now my error has changed to:

Traceback (most recent call last):
File "F:\images2\align_01.py", line 32, in <module>
matches = tuple(sorted(key = lambda x:x.distance))
TypeError: sorted expected 1 argument, got 0


Could you please look into the error and suggest me how to go further?

Thanks & Regards,
Utkarsha.
Reply
#5
You did not try my suggestion to add the name of the original tuple as the first argument of sorted().
Reply
#6
(Feb-25-2022, 12:05 PM)ibreeden Wrote: You did not try my suggestion to add the name of the original tuple as the first argument of sorted().

Thank you @ibreeden , now as per your suggestion i have added the first argument of sorted() and it is working!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020