Fix: Tesseract 3.04 is sensitive to order of configuration commands

“txt hocr” is not acceptable and does not produce expected output .txt
while “hocr text” works fine, so switch the order everywhere.

Should fix #169
This commit is contained in:
James R. Barlow
2017-05-14 23:27:46 -07:00
parent fb067dc97b
commit 234183ecd2
5 changed files with 15 additions and 12 deletions
+5 -4
View File
@@ -43,7 +43,6 @@ HOCR_TEMPLATE = '''<?xml version="1.0" encoding="UTF-8"?>
</body>
</html>'''
@lru_cache(maxsize=1)
def version():
args_tess = [
@@ -229,11 +228,13 @@ def generate_hocr(input_file, output_files, language: list, engine_mode,
# Reminder: test suite tesseract spoofers will break after any changes
# to the number of order parameters here
# Tesseract 3.04 requires the order here to be "hocr txt" and will fail
# on "txt hocr"
args_tesseract.extend([
input_file,
prefix,
'txt',
'hocr'
'hocr',
'txt'
] + tessconfig)
try:
log.debug(args_tesseract)
@@ -316,8 +317,8 @@ def generate_pdf(*, input_image, skip_pdf, output_pdf, output_text,
args_tesseract.extend([
input_image,
prefix,
'txt',
'pdf',
'txt'
] + tessconfig)
try:
+2 -2
View File
@@ -20,11 +20,11 @@ def main():
elif sys.argv[1] == '--list-langs':
print('List of available languages (1):\neng', file=sys.stderr)
sys.exit(0)
elif sys.argv[-1] == 'hocr':
elif sys.argv[-2] == 'hocr':
print("Image too large: (33830, 14959)\n"
"Error during processing.", file=sys.stderr)
sys.exit(1)
elif sys.argv[-1] == 'pdf':
elif sys.argv[-2] == 'pdf':
print("Image too large: (33830, 14959)\n"
"Error during processing.", file=sys.stderr)
sys.exit(1)
+4 -2
View File
@@ -35,10 +35,12 @@ def real_tesseract():
return # Not reachable
def main():
operation = sys.argv[-1]
operation = sys.argv[-2]
sidecar = False
if sys.argv[-2] == 'txt':
if sys.argv[-1] == 'txt':
sidecar = True
elif sys.argv[-1] == 'stdout':
operation = 'stdout'
# For anything unexpected operation, defer to real tesseract binary
# Currently this includes all use of "--tesseract-config"
+2 -2
View File
@@ -28,10 +28,10 @@ def main():
elif sys.argv[1] == '--list-langs':
print('List of available languages (1):\neng', file=sys.stderr)
sys.exit(0)
elif sys.argv[-1] == 'hocr':
elif sys.argv[-2] == 'hocr':
print("KABOOM! Tesseract failed for some reason", file=sys.stderr)
sys.exit(128 + signal.SIGSEGV)
elif sys.argv[-1] == 'pdf':
elif sys.argv[-2] == 'pdf':
print("KABOOM! Tesseract failed for some reason", file=sys.stderr)
sys.exit(128 + signal.SIGSEGV)
elif sys.argv[-1] == 'stdout':
+2 -2
View File
@@ -52,7 +52,7 @@ def main():
elif sys.argv[1] == '--list-langs':
print('List of available languages (1):\neng', file=sys.stderr)
sys.exit(0)
elif sys.argv[-1] == 'hocr':
elif sys.argv[-2] == 'hocr':
inputf = sys.argv[-4]
output = sys.argv[-3]
with Image.open(inputf) as im, \
@@ -61,7 +61,7 @@ def main():
f.write(HOCR_TEMPLATE.format(str(w), str(h)))
with open(output + '.txt', 'w') as f:
f.write('')
elif sys.argv[-1] == 'pdf':
elif sys.argv[-2] == 'pdf':
inputf = sys.argv[-4]
output = sys.argv[-3]
pdf_bytes = img2pdf.convert([inputf], dpi=300)