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
24.41k stars 3.16k forks source link

Vertical margins in the detected boxes from easyocr.detect don't have a consistent behavior #360

Closed fxmarty closed 3 years ago

fxmarty commented 3 years ago

When setting add_margin=0 (not sure about other cases), some boxes detected with easyocr.detect still have a border while some don't, as illustrated below.

How to reproduce

Download 花火 Fireworks 1997 iNT DVDRip XviD0316

Execute

import torch
from easyocr import Reader
import numpy as np
import cv2
import matplotlib.pyplot as plt

reader = Reader(['ja'])

filename = '/path/to/file.png' # change accordingly
img = cv2.imread(filename, 1)

# Here we add some white border to the image
h,w=img.shape[0:2]
border = 50
base_size=h+border,w+border,3
base=np.zeros(base_size,dtype=np.uint8) + 255
base[border//2:border//2 + h, border//2:border//2 + w]=img

# Detect boxes, without margins
result = reader.detect(base, add_margin=0)

Then execute

k = result[0][0]
cv2.rectangle(base, (k[1], k[3]),
            (k[0], k[2]),
            (0,0,255),
            1)

plt.imshow(base)
plt.show()

and

k = result[0][1]
cv2.rectangle(base, (k[1], k[3]),
            (k[0], k[2]),
            (0,0,255),
            1)

plt.imshow(base)
plt.show()

This returns image

and image

As you can see, the first one has borders, while the second do not.

I guess it is not too big of an issue, and it can be solved manually, but still, it is not expected behavior here.

Thank you!

rkcosmos commented 3 years ago

add_margin is an extra margin in addition to the output from text detection. Text detection is deep learning-based algorithm and may introduce its own small margin.

fxmarty commented 3 years ago

I see, seems very reasonable. Thank you for your help.