Skip to content

Commit

Permalink
Merge pull request #12 from hv0905/better-preprocess
Browse files Browse the repository at this point in the history
Improve OCR preprocess procedure. Improve performance.
  • Loading branch information
hv0905 authored Jan 5, 2024
2 parents a230014 + 1bee16c commit 14bb34d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit 14bb34d

Please sign in to comment.