Skip to content

Commit

Permalink
Update quickstart_en.md (#11934)
Browse files Browse the repository at this point in the history
* Update quickstart_en.md

sync quickstart cn doc's better pdf demo

* Update quickstart.md

revert font location changes of the demo code

* Update quickstart_en.md

revert font location changes of the en demo code
  • Loading branch information
qwedc001 authored Apr 16, 2024
1 parent 6fdce04 commit 2965012
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/doc_ch/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ for idx in range(len(result)):
boxes = [line[0] for line in res]
txts = [line[1][0] for line in res]
scores = [line[1][1] for line in res]
im_show = draw_ocr(image, boxes, txts, scores, font_path='simfang.ttf')
im_show = draw_ocr(image, boxes, txts, scores, font_path='doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result_page_{}.jpg'.format(idx))
```
Expand Down
25 changes: 15 additions & 10 deletions doc/doc_en/quickstart_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,34 +224,39 @@ from paddleocr import PaddleOCR, draw_ocr
# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `fr`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang="ch", page_num=2) # need to run only once to download and load model into memory
img_path = './xxx.pdf'
result = ocr.ocr(img_path, cls=True)
PAGE_NUM = 10 # Set the recognition page number
pdf_path = 'default.pdf'
ocr = PaddleOCR(use_angle_cls=True, lang="ch", page_num=PAGE_NUM) # need to run only once to download and load model into memory
# ocr = PaddleOCR(use_angle_cls=True, lang="ch", page_num=PAGE_NUM,use_gpu=0) # To Use GPU,uncomment this line and comment the above one.
result = ocr.ocr(pdf_path, cls=True)
for idx in range(len(result)):
res = result[idx]
if res == None: # Skip when empty result detected to avoid TypeError:NoneType
print(f"[DEBUG] Empty page {idx+1} detected, skip it.")
continue
for line in res:
print(line)

# draw result
# draw the result
import fitz
from PIL import Image
import cv2
import numpy as np
imgs = []
with fitz.open(img_path) as pdf:
for pg in range(0, pdf.pageCount):
with fitz.open(pdf_path) as pdf:
for pg in range(0, PAGE_NUM):
page = pdf[pg]
mat = fitz.Matrix(2, 2)
pm = page.getPixmap(matrix=mat, alpha=False)
pm = page.get_pixmap(matrix=mat, alpha=False)
# if width or height > 2000 pixels, don't enlarge the image
if pm.width > 2000 or pm.height > 2000:
pm = page.getPixmap(matrix=fitz.Matrix(1, 1), alpha=False)

pm = page.get_pixmap(matrix=fitz.Matrix(1, 1), alpha=False)
img = Image.frombytes("RGB", [pm.width, pm.height], pm.samples)
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
imgs.append(img)
for idx in range(len(result)):
res = result[idx]
if res == None:
continue
image = imgs[idx]
boxes = [line[0] for line in res]
txts = [line[1][0] for line in res]
Expand Down

0 comments on commit 2965012

Please sign in to comment.