0

I am working with Paddle OCR, I would like to know what is the output format for bbx off paddle OCR. I can not find in the github of Paddle. Here is my code.

from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(use_angle_cls=False, lang='en', rec=False) # need to run only once to download and load model into memory

result = ocr.ocr(img, cls=False)

Output

[[[[8.0, 12.0], [89.0, 12.0], [89.0, 25.0], [8.0, 25.0]],
  ('@kheengz_yfk', 0.9460259079933167)],
 [[[6.0, 31.0], [227.0, 29.0], [227.0, 44.0], [6.0, 46.0]],
  ('EBIT is a week old today. and', 0.847086489200592)],
 [[[4.0, 47.0], [225.0, 49.0], [225.0, 64.0], [4.0, 62.0]],
  ('the homebors came together...Seemore', 0.942597508430481)],
 [[[7.0, 70.0], [183.0, 70.0], [183.0, 83.0], [7.0, 83.0]],
  ('Joriginal sound-kheengz_yfk(Cont', 0.8839073181152344)]]

I want to manually draw Bounding Boxes against it.

My thinking is that first is x0,y0(top left) and last is x1,y1(bot right)

rect = cv2.rectangle(img.copy(), (int(result[0][0][0][0]), int(result[0][0][0][1])), (int(result[0][0][-1][0]),int(result[0][0][-1][0]) ), (0, 255, 0), -1)

plt.imshow(rect)

But this does not work correctly. Any help in this. Thanks.

Testing Image.

enter image description here

Orignal Paddle OCR draw_ocr output.

from PIL import Image
image = Image.fromarray(img).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='/usr/share/fonts/opentype/malayalam/Chilanka-Regular.otf')
plt.imshow(im_show)

enter image description here

Ahmad Anis
  • 2,322
  • 4
  • 25
  • 54

1 Answers1

3

To draw all of your boxes, assuming your image has been loaded with PIL.Image.open() and is called thisImage and that you've got a PaddleOCR result called result

draw = PIL.ImageDraw.Draw(thisImage)
for i, box in enumerate(result[0]):
    box = np.array(box[0]).astype(np.int32)
    xmin = min(box[:, 0])
    ymin = min(box[:, 1])
    xmax = max(box[:, 0])
    ymax = max(box[:, 1])
    draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
    draw.text((xmin, ymin), f"{i}", fill="black")

(in this case I've added the result index number to the box for cross-reference)

James_SO
  • 1,169
  • 5
  • 11
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 31 '22 at 06:58