From b49f5a7d7716b1effba05c424b841c72b16c3da2 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 4 Dec 2015 01:35:07 -0800 Subject: [PATCH] Support optionally using leptonica to deskew unpaper doesn't seem to be good at deskewing. It fails on test case with a lot of italics. I think it also struggles on pages with a lot of whitespace. Leptonica continues to shine here. However, this is only a first crack at Leptonica. The leptonica module should be redone to use cffi (more extensible). Also considering the possibility of making all Lept calls in a forked process to insulate the calling process from C code crashes and the messy redirect of stdout/stderr to read Leptonica's errors. I don't think the redirect is a huge problem as long as multiprocesses rather than multithreads are used. The ruffus child process that is handling a page is single threaded and will not be affected by the redirection. It just feels dirty. The main reason to consider a child process is crash isolation. --- ocrmypdf/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index c8ade0ae..3790bd92 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -185,6 +185,9 @@ advanced.add_argument( '--tesseract-timeout', default=180.0, type=float, metavar='SECONDS', help='give up on OCR after the timeout, but copy the preprocessed page ' 'into the final output') +advanced.add_argument( + '--deskewer', choices=['leptonica', 'unpaper'], default='leptonica', + help='choose deskew provider') debugging = parser.add_argument_group( "Debugging", @@ -493,7 +496,11 @@ def preprocess_deskew( pageinfo = get_pageinfo(input_file, pdfinfo, pdfinfo_lock) dpi = int(pageinfo['xres']) - unpaper.deskew(input_file, output_file, dpi, log) + if options.deskewer == 'unpaper': + unpaper.deskew(input_file, output_file, dpi, log) + else: + from . import leptonica + leptonica.deskew(input_file, output_file, dpi) @transform(