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

Test EasyOCR/PyTesseract/PaddleOCR #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 35 additions & 2 deletions gui_agents/utils/ocr_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
ocr_module = PaddleOCR(use_angle_cls=True, lang="en")


def text_cvt_orc_format_easyocr(easyocr_result):
"""
Convert EasyOCR results into the required format.
"""
texts = []
for i, line in enumerate(easyocr_result):
bbox, content, _ = line
location = {
"left": int(bbox[0][0]),
"top": int(bbox[0][1]),
"right": int(bbox[2][0]),
"bottom": int(bbox[2][1]),
}
texts.append((i, content, location))
return texts

import easyocr
import numpy as np

easyocr_reader = easyocr.Reader(["en"])

def ocr_results_easyocr(screenshot):
"""
Perform OCR using EasyOCR and return results.
"""
screenshot_img = Image.open(io.BytesIO(screenshot))
if screenshot_img.mode != "RGB":
screenshot_img = screenshot_img.convert("RGB")
easyocr_result = easyocr_reader.readtext(np.array(screenshot_img))
return text_cvt_orc_format_easyocr(easyocr_result)


class ImageData(BaseModel):
img_bytes: bytes

Expand Down Expand Up @@ -39,12 +71,13 @@ def ocr_results(screenshot):
result = ocr_module.ocr(np.array(screenshot_img), cls=True)
return text_cvt_orc_format_paddle(result)

print("ocr_module: ", easyocr_reader)

@app.post("/ocr/")
async def read_image(image_data: ImageData):
image_bytes = base64.b64decode(image_data.img_bytes)
results = ocr_results(image_bytes)

results = ocr_results_easyocr(image_bytes)
print("Received easyOCR response.")
# Explicitly delete unused variables and run garbage collector
del image_bytes
gc.collect()
Expand Down
1,130 changes: 1,130 additions & 0 deletions tmp.ipynb

Large diffs are not rendered by default.

Loading