fix: Ensure that TesseractOcrModel does not crash in case OSD is not installed (#1866)

fix: Ensure that TesseractOcrModel does not crash if tesseract OSD is not installed

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
This commit is contained in:
Nikos Livathinos 2025-06-30 10:55:56 +02:00 committed by GitHub
parent bb99be6c24
commit ae39a9411a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -144,7 +144,10 @@ class TesseractOcrModel(BaseOcrModel):
local_reader = self.reader
self.osd_reader.SetImage(high_res_image)
doc_orientation = 0
osd = self.osd_reader.DetectOrientationScript()
# No text, or Orientation and Script detection failure
if osd is None:
_log.error(
@ -158,11 +161,14 @@ class TesseractOcrModel(BaseOcrModel):
# to OCR in the hope OCR will succeed while OSD failed
if self._is_auto:
continue
doc_orientation = parse_tesseract_orientation(osd["orient_deg"])
if doc_orientation != 0:
high_res_image = high_res_image.rotate(
-doc_orientation, expand=True
else:
doc_orientation = parse_tesseract_orientation(
osd["orient_deg"]
)
if doc_orientation != 0:
high_res_image = high_res_image.rotate(
-doc_orientation, expand=True
)
if self._is_auto:
script = osd["script_name"]
script = map_tesseract_script(script)