})
def _load_sample(self, sample, text_only):
image_path = sample["image_path"]
line = sample["line"]
text = None
img = None
if self.mode == DataSetMode.EVAL or self.mode == DataSetMode.TRAIN:
text = sample["format"].text
if text_only:
return img, text
if self.mode == DataSetMode.TRAIN or self.mode == DataSetMode.PREDICT:
img = np.array(Image.open(image_path))
ly, lx = img.shape
// Cut the Image
img = img[line.rect.top: -ly + line.rect.bottom, line.rect.left: -lx + line.rect.right]
// add padding as required from normal files
img = np.pad(img, ((3, 3), (0, 0)), mode="constant", constant_values=img.max())
Binarize Image
if self.binary:
img = img > 0.9
After Change
for l, line in enumerate(page.getLines()):
for f, fo in enumerate(line.formats):
text = None
cut_img = None
if self.mode == DataSetMode.EVAL or self.mode == DataSetMode.TRAIN:
text = fo.text