Open CV - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Open CV (/thread-36492.html) |
Open CV - Utkarsha - Feb-25-2022 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-registration-using-opencv-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. RE: Open CV - Axel_Erfurt - Feb-25-2022 maybe matches = tuple(sorted(key = x.distance)) RE: Open CV - ibreeden - Feb-25-2022 (Feb-25-2022, 05:47 AM)Utkarsha Wrote: matches.sort(key = lambda x: x.distance)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.) RE: Open CV - Utkarsha - Feb-25-2022 (Feb-25-2022, 10:22 AM)ibreeden Wrote:(Feb-25-2022, 05:47 AM)Utkarsha Wrote: matches.sort(key = lambda x: x.distance)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: 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. RE: Open CV - ibreeden - Feb-25-2022 You did not try my suggestion to add the name of the original tuple as the first argument of sorted(). RE: Open CV - Utkarsha - Feb-27-2022 (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! |