From 7e776612a48aaab0bfc672f6600f9902738e1fb7 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 18 Jul 2026 00:35:50 +0200 Subject: [PATCH] =?UTF-8?q?cnn-rnn-ocr:=20if=20`dir=5Fin=5Fbin=3D=3Ddir=5F?= =?UTF-8?q?in`,=20then=20split=20PNG=20and=20rest=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (supports common case that binarized images have same stem, but different file name extension) --- src/eynollah/eynollah_ocr.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/eynollah/eynollah_ocr.py b/src/eynollah/eynollah_ocr.py index 434b865..4d82fb7 100644 --- a/src/eynollah/eynollah_ocr.py +++ b/src/eynollah/eynollah_ocr.py @@ -5,6 +5,7 @@ import logging import logging.handlers from typing import List, Optional from pathlib import Path +from itertools import groupby import os import gc import math @@ -459,6 +460,18 @@ class Eynollah_ocr(Eynollah): ls_imgs = [os.path.join(dir_in, image_filename) for image_filename in filter(is_image_filename, os.listdir(dir_in))] + if dir_in_bin and dir_in_bin == dir_in: + # try filtering PNGs from rest + def pathstem(filename): + return os.path.splitext(filename)[0] + def notpng(filenames): + for filename in filenames: + if not filename.lower().endswith(".png"): + return filename + return filenames[0] + ls_imgs = [notpng(files) + for _, files in groupby(sorted(ls_imgs), + key=pathstem)] with ProcessPoolExecutor(max_workers=num_jobs or None, mp_context=mp.get_context('fork'), initializer=_set_instance,