JaidedAI / EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.
https://www.jaided.ai
Apache License 2.0
23.61k stars 3.1k forks source link

Box detection seems off #1199

Open tommedema opened 8 months ago

tommedema commented 8 months ago

Take this sample code:

import cv2
import easyocr
from PIL import Image

# Initialize EasyOCR Reader
reader = easyocr.Reader(['en'])

image_path = 'imessage2.png'

image = cv2.imread(image_path)

print(f"Detecting boxes for image with dimensions (HxW): {image.shape[0]}x{image.shape[1]}")

# Use EasyOCR to detect text regions
[[horizontal_list], _] = reader.detect(image, min_size = 1, canvas_size = 2560, mag_ratio = 1, add_margin = 0.1, text_threshold = 0.5, low_text = 0.4, width_ths = 0.9, height_ths = 0.5, ycenter_ths = 0.5, slope_ths = 0.1)

for i, box in enumerate(horizontal_list):
    x_min, x_max, y_min, y_max = box

    # Crop the region of interest (ROI) from the image
    roi = image[y_min:y_max, x_min:x_max]

    roi_filename = f"boxes/box_{i}.png"
    cv2.imwrite(roi_filename, roi)

With the below image imessage2.png:

imessage2

No matter which width_ths, low_text, and text_threshold arguments I pass in, I keep getting a bounding box that is missing real text data:

box_0

when I increase slope_ths to 0.3 I do get "you" on there:

box_0

but no matter what I do I don't seem to get "I" on there, unless I set low_text to something really low like 0.1 but then all my other boxes are very off.

running this on MacOS Sonoma, Apple M2

magnusahlden commented 6 months ago

I get the same problems for many items. Is there really no way to manually set the bounding boxes? I get maybe 1-5 hits for each sentence (all of them missing a few characters).