CRAFT-pytorch
CRAFT-pytorch copied to clipboard
Question about the sorting algorithm
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
From my past experience, you can easily stable-sort all bounding boxes by y coordinates and then by x coordinates.
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
Hi @iknoorjobs did you find any solution ?
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!