Home > Blockchain >  Numpy Sort 3D Array of Coordinates
Numpy Sort 3D Array of Coordinates

Time:11-29

I got a 3D array of rects' coordinates from Credit Card

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.

  • Related