-
Notifications
You must be signed in to change notification settings - Fork 20
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
easyOCR evaluation #8
Comments
Thank you for your attention. We will gradually add more models to the evaluation leaderboard, and the easyOCR results will be updated in the OCR module. |
Hi, we evaluate the EasyOCR in Omnidocbench at OCR module. Here is the result:
This is our model inference code for EasyOCR, aligned with model inference code for other model, adding a 50-pixel white border to each image. import cv2
import numpy as np
from pathlib import Path
import pdb
import sys
from tqdm import tqdm
import logging
import os
import json
import numpy
from PIL import Image, ImageOps
import easyocr
import pdb
def model_infer(engine, img, lan, img_name):
img_add_border = add_white_border(img)
img_ndarray = numpy.array(img_add_border)
# img = cv2.imdecode(img_ndarray, cv2.IMREAD_COLOR)
tmp_img_path = f'tmp_easyocr.jpg'
cv2.imwrite(tmp_img_path, img_ndarray)
result = engine.readtext(tmp_img_path)
text = ''
for idx in range(len(result)):
res = result[idx]
t = res[1]
text += t
return text
def add_white_border(img: Image):
border_width = 50
border_color = (255, 255, 255)
img_with_border = ImageOps.expand(img, border=border_width, fill=border_color)
return img_with_border
def poly2bbox(poly):
L = poly[0]
U = poly[1]
R = poly[2]
D = poly[5]
L, R = min(L, R), max(L, R)
U, D = min(U, D), max(U, D)
bbox = [L, U, R, D]
return bbox
def main():
engine = easyocr.Reader(['ch_sim','en'])
with open('./OmniDocBench/OmniDocBench.json', 'r') as f:
samples = json.load(f)
for sample in samples:
img_name = os.path.basename(sample['page_info']['image_path'])
img_path = os.path.join('./OmniDocBench/images', img_name)
img = Image.open(img_path)
if not os.path.exists(img_path):
print('No exist: ', img_name)
continue
for i, anno in enumerate(sample['layout_dets']):
if not anno.get('text'):
continue
# print(anno)
lan = anno['attribute'].get('text_language', 'mixed')
bbox = poly2bbox(anno['poly'])
image = img.crop(bbox).convert('RGB') # crop text block
outputs = model_infer(engine, image, lan, img_name)
anno['pred'] = outputs
with open('./OmniDocBench/result/OmniDocBench_easyocr_text_ocr.jsonl', 'a', encoding='utf-8') as f:
json.dump(sample, f, ensure_ascii=False)
f.write('\n')
def save_json():
with open('./OmniDocBench/result/OmniDocBench_easyocr_text_ocr.jsonl', 'r') as f:
lines = f.readlines()
samples = [json.loads(line) for line in lines]
with open('./OmniDocBench/result/OmniDocBench_easyocr_text_ocr.json', 'w', encoding='utf-8') as f:
json.dump(samples, f, indent=4, ensure_ascii=False)
if __name__ == '__main__':
main()
save_json() Please let us know if there are any issues in the infer code. |
This is amazing work! Any plans to include easyOCR in the benchmark?
https://github.com/JaidedAI/EasyOCR
Secondary ask is if you have a prioritized list of other languagesm
The text was updated successfully, but these errors were encountered: