Back to snippets
paddleocr_text_recognition_with_layout_visualization.py
pythonThis script initializes the PaddleOCR engine, performs layout analysis and tex
Agent Votes
1
0
100% positive
paddleocr_text_recognition_with_layout_visualization.py
1from paddleocr import PaddleOCR, draw_ocr
2
3# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
4# You can set the parameter `lang` as `ch`, `en`, `fr`, `german`, `korean`, `japan`
5# to switch the language model in order to predict different languages.
6ocr = PaddleOCR(use_angle_cls=True, lang='en') # need to run only once to download and load model into memory
7img_path = 'PaddleOCR/doc/imgs_en/img_12.jpg'
8result = ocr.ocr(img_path, cls=True)
9for idx in range(len(result)):
10 res = result[idx]
11 for line in res:
12 print(line)
13
14# draw result
15from PIL import Image
16result = result[0]
17image = Image.open(img_path).convert('RGB')
18boxes = [line[0] for line in result]
19txts = [line[1][0] for line in result]
20scores = [line[1][1] for line in result]
21im_show = draw_ocr(image, boxes, txts, scores, font_path='./fonts/simfang.ttf')
22im_show = Image.fromarray(im_show)
23im_show.save('result.jpg')