Check autorotate using leptonica correlation

This commit is contained in:
James R. Barlow
2016-02-08 12:55:50 -08:00
parent 98c115e3bb
commit 78c3bf5dba
3 changed files with 15 additions and 0 deletions
+8
View File
@@ -193,6 +193,14 @@ def deskew(infile, outfile, dpi):
raise LeptonicaIOError("Failed to open destination file: %s" % outfile)
def correlation_binary(pix1, pix2):
correlation = ffi.new('float *', 0.0)
result = lept.pixCorrelationBinary(pix1, pix2, correlation)
if result != 0:
raise LeptonicaError("Correlation failed")
return correlation[0]
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Python wrapper to access Leptonica")
+1
View File
@@ -52,6 +52,7 @@ l_int32 pixWriteImpliedFormat ( const char *filename, PIX *pix, l_int32 quality,
void pixDestroy ( PIX **ppix );
PIX * pixDeskew ( PIX *pixs, l_int32 redsearch );
char * getLeptonicaVersion ( );
l_int32 pixCorrelationBinary(PIX *pix1, PIX *pix2, l_float32 *pval);
""")
if __name__ == '__main__':
+6
View File
@@ -11,6 +11,7 @@ import pytest
from ocrmypdf.pageinfo import pdf_get_all_pageinfo
import PyPDF2 as pypdf
from ocrmypdf import ExitCode
from ocrmypdf import leptonica
if sys.version_info.major < 3:
@@ -259,6 +260,11 @@ def test_autorotate(spoof_tesseract_cache, renderer):
_make_input('cardinal.pdf'), _make_output('reference.png'),
xres=100, yres=100, raster_device='pngmono', log=gslog, pageno=1)
pix_ref = leptonica.pixRead(_make_output('reference.png'))
for n in range(1, 4+1):
pix_other = leptonica.pixRead(_make_output('cardinal-%i.png' % n))
print(leptonica.correlation_binary(pix_ref, pix_other))
@pytest.mark.parametrize('renderer', [
'hocr',