CRAFT-pytorch icon indicating copy to clipboard operation
CRAFT-pytorch copied to clipboard

Question about the sorting algorithm

Open iknoorjobs opened this issue 4 years ago • 4 comments

Hi

I have one question about the order of bounding boxes generated by the model. The model on the demo page (https://clova.ai/ocr) works quite good in sorting the bounding boxes as well as handling most of the images with tilted words. Could you please tell how the sorting algorithm is implemented to sort the boxes as per text?

Thank you so much.

Iknoor

iknoorjobs avatar Aug 31 '20 17:08 iknoorjobs

From my past experience, you can easily stable-sort all bounding boxes by y coordinates and then by x coordinates.

jimlinntu avatar Sep 07 '20 08:09 jimlinntu

Hi @jimlinntu Thanks. This is something which I have already implemented but it fails to work on tilted text and some ambiguous cases. But the demo model on Clova works quite good in handling such cases.

Regards Iknoor

iknoorjobs avatar Sep 07 '20 08:09 iknoorjobs

Hi @iknoorjobs did you find any solution ?

gupta33 avatar Jan 14 '21 12:01 gupta33

For anybody who comes here searching for the same problem, you can get the cropped out image from coordinates stored in .txt files using the code snippet below:

from PIL import Image

# here is the bounding box
x1, y1, x2, y2, x3, y3, x4, y4 = [168,377,189,377,189,386,168,386]

# get the corners
top_left_x = min([x1,x2,x3,x4])
top_left_y = min([y1,y2,y3,y4])
bot_right_x = max([x1,x2,x3,x4])
bot_right_y = max([y1,y2,y3,y4])

# crop the image
Image.fromarray(image[top_left_y:bot_right_y+1, top_left_x:bot_right_x+1])

Hope this helps!

DhruvAwasthi avatar Feb 07 '21 12:02 DhruvAwasthi