1

i used this code to detect all texts and draw all bouding boxes:

from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(lang='en') # need to run only once to download and load model into memory
img_path = 'PaddleOCR/doc/imgs_en/img_12.jpg'
result = ocr.ocr(img_path, cls=False)
for line in result:
    print(line)

# draw result
from PIL import Image
image = Image.open(img_path).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='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

Now i have an image with all detected bouding boxes. I want to seperate all bouding boxes so that i can extract the Information from them with pytesseract. I want to do this because paddleocr is better for detection but Pytesserat is better for extraction (german language). So how can i seperate all bouding boxes to extract the text from eeach of them ? Thank you

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • so you already have those rectangles including characters inside. Then create a sub-Mat by cropping each rectangles and apply Pytesseract by one by – Yunus Temurlenk Jul 02 '22 at 18:14
  • thank you for your answer. this is the coordinate that i have with paddle ocr: ```[[338.0, 487.0], [414.0, 487.0], [414.0, 527.0], [338.0, 527.0]] [[335.0, 439.0], [431.0, 439.0], [431.0, 484.0], [335.0, 484.0]]``` So can you tell me how can i use them to crop the rectangles ? – Atef Chatty Jul 02 '22 at 20:54
  • similar to thi `cropped_image = img[80:280, 150:330]` – Yunus Temurlenk Jul 03 '22 at 07:56

1 Answers1

0

the order of the four points in each detection box is upper left, upper right, lower right, and lower left.

Since the detection algorithm in PP-OCR is detected by line, if you want to get the specific coordinates of each word from the detection box coordinates, it will be more difficult.

Leif Zhu
  • 16
  • 1