leptonica.py: Fix exception on certain types of barcode failures

Closes #322
This commit is contained in:
James R. Barlow
2018-12-19 17:23:23 -08:00
parent 40b72b0fa8
commit 1ca1221432
2 changed files with 10 additions and 4 deletions
+3 -1
View File
@@ -17,7 +17,9 @@ Note that it is licensed under GPLv3, so scripts that ``import ocrmypdf`` and ar
v7.4.1
------
- Fix a few documentation problems.
- Fixed a few documentation problems.
- Fixed an unhandled exception when attempting to mask barcodes. #322 <https://github.com/jbarlow83/OCRmyPDF/issues/322>`_
v7.4.0
------
+7 -3
View File
@@ -567,8 +567,8 @@ class Pix(LeptonicaObject):
with _LeptonicaErrorTrap():
pix = Pix(lept.pixConvertTo8(self._cdata, 0))
pixa_candidates = PixArray(lept.pixExtractBarcodes(pix._cdata, 0))
with suppress(FileNotFoundError):
os.unlink('junkpixt.png') # leptonica may produce this
if not pixa_candidates:
return
sarray = StringArray(lept.pixReadBarcodes(
pixa_candidates._cdata,
lept.L_BF_ANY,
@@ -576,8 +576,12 @@ class Pix(LeptonicaObject):
ffi.NULL,
0
))
except (LeptonicaError, ValueError) as e:
except (LeptonicaError, ValueError, IndexError) as e:
return
finally:
with suppress(FileNotFoundError):
os.unlink('junkpixt.png') # leptonica may produce this
os.unlink('junkpixt')
for n, s in enumerate(sarray):
decoded = s.decode()