Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve OCR preprocess procedure. Improve performance. #12

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/Services/ocr_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ class EasyPaddleOCRService(OCRService):
def __init__(self):
super().__init__()
from easypaddleocr import EasyPaddleOCR
self._paddle_ocr_module = EasyPaddleOCR(use_angle_cls=True, needWarmUp=True, devices=self._device)
self._paddle_ocr_module = EasyPaddleOCR(use_angle_cls=True,
needWarmUp=True,
devices=self._device,
warmup_size=(960, 960))
logger.success("EasyPaddleOCR loaded successfully")

@staticmethod
def _image_preprocess(img: Image.Image) -> Image.Image:
# Optimized `easypaddleocr` doesn't require scaling preprocess
if img.mode != 'RGB':
img = img.convert('RGB')
return img

def _easy_paddleocr_process(self, img: Image.Image) -> str:
_, ocr_result, _ = self._paddle_ocr_module.ocr(np.array(img))
if ocr_result:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pillow>9.3.0
numpy

# OCR - you can choose other option if necessary, or completely disable it if you don't need this feature
easypaddleocr
easypaddleocr>=0.1.2
# easyocr
# paddleocr

Expand Down