I got a 3D array of rects' coordinates from
The problem is that the text Adrian W.
is placed first since it is the leftmost text on the card. How can we use Numpy sort such that the order of the detected text would be:
HSBC..
, world
, the card number from left to right 5183, 2301, 1234, 5678
, valid date
, Adrian W.
which means that we sort the texts by using the y coordinate of the top-left point of each rect's and only sort by x if there are same y coordinates?
CodePudding user response:
which means that we sort the texts by using the y coordinate of the top-left point of each rect's and only sort by x if there are same y coordinates?
Wouldn't the following give you the desired result?
arr = sorted(arr, key=lambda x: (x[0][1], x[0][0]))
Then you can add arr = np.array(arr)
to get a numpy array.