This commit is contained in:
Robert Sachunsky 2026-02-03 14:36:39 +01:00 committed by GitHub
commit dda8454236
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 12 deletions

View file

@ -14,16 +14,7 @@ from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor
from eynollah.model_zoo.model_zoo import EynollahModelZoo
from .sbb_binarize import SbbBinarizer
def cv2pil(img):
return Image.fromarray(img.astype('uint8'))
def pil2cv(img):
# from ocrd/workspace.py
color_conversion = cv2.COLOR_GRAY2BGR if img.mode in ('1', 'L') else cv2.COLOR_RGB2BGR
pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img)
return cv2.cvtColor(pil_as_np_array, color_conversion)
from .utils.pil_cv2 import cv2pil, pil2cv
class SbbBinarizeProcessor(Processor):
# already employs GPU (without singleton process atm)

View file

@ -7,12 +7,18 @@ from cv2 import COLOR_GRAY2BGR, COLOR_RGB2BGR, COLOR_BGR2RGB, cvtColor, imread
# from sbb_binarization
def cv2pil(img):
return Image.fromarray(np.array(cvtColor(img, COLOR_BGR2RGB)))
# reduce depth because cvtColor is limited
return Image.fromarray(np.array(cvtColor(img.astype(np.uint8), COLOR_BGR2RGB)))
def pil2cv(img):
# from ocrd/workspace.py
color_conversion = COLOR_GRAY2BGR if img.mode in ('1', 'L') else COLOR_RGB2BGR
color_conversion = COLOR_GRAY2BGR if img.mode in ('1', 'L', 'LA') else COLOR_RGB2BGR
pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img)
# cvtColor cannot handle alpha
if pil_as_np_array.shape[-1] == 2:
pil_as_np_array = pil_as_np_array[:,:,0]
elif pil_as_np_array.shape[-1] == 4:
pil_as_np_array = pil_as_np_array[:,:,:3]
return cvtColor(pil_as_np_array, color_conversion)
def check_dpi(img):