Skip to content

Commit

Permalink
Keep the initial preprocessing and adjust the EasyPaddleOCR preproc…
Browse files Browse the repository at this point in the history
…essing to include only RGB conversion.
  • Loading branch information
pk5ls20 committed Jan 4, 2024
1 parent ad11c0d commit 1bee16c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/Services/ocr_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def __init__(self):
def _image_preprocess(img: Image.Image) -> Image.Image:
if img.mode != 'RGB':
img = img.convert('RGB')
# Limit maximum size to 960*960
if img.size[0] > 960 or img.size[1] > 960:
img.thumbnail((960, 960), Image.Resampling.LANCZOS)
return img
if img.size[0] > 1024 or img.size[1] > 1024:
img.thumbnail((1024, 1024), Image.Resampling.LANCZOS)
new_img = Image.new('RGB', (1024, 1024), (0, 0, 0))
new_img.paste(img, ((1024 - img.size[0]) // 2, (1024 - img.size[1]) // 2))
return new_img

def ocr_interface(self, img: Image.Image, need_preprocess=True) -> str:
pass
Expand All @@ -37,6 +38,13 @@ def __init__(self):
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

0 comments on commit 1bee16c

Please sign in to comment.