tesseract icon indicating copy to clipboard operation
tesseract copied to clipboard

Parts of lines of columnar data are split into separate areas in output

Open RanTalbott opened this issue 1 year ago • 1 comments

Current Behavior

I'm OCRing old bank statements to extract transaction information. Sample of the transaction area attached (the gray areas at the left and right edges are from the PDF viewer. Left in to show the width of the page. Full images not attached because they're 22MB each and contain bank info). Usually, everything goes well: character recognition is better than 99.9% accurate, and all the text from each line is output as a single line. But sometimes the output from one of the 3 or 4 statement pages is scrambled, while the others scan correctly. In some cases, the date columns are output before the rest of the page: first the transaction dates, then the posting dates, the the rest of the text. In others, the amount columns come out after: so far it appears that both amounts always come out on a single line.

I convert the PDF to a TIFF with ghostscript, and invoke Tesseract with no parameters: gs -q -dNOPAUSE -r288 -sDEVICE=tiffgray -sOutputFile=$tiffname $pdfname -c quit tesseract $tiffname ascu$1

I've spot-checked a few of the TIFFs, and they're correct renderings of the PDFs.

I've looked for differences in the transaction text (like longer lines) that might trigger this behavior, but haven't spotted any. Maybe I don't know what to look for? Is it possible that there's something in a page heading that I don't know about that tells Tesseract "Treat this page differently from the others"?

Out of 12 statements scanned, 4 had anomalies with the separated amounts. One also separated the dates. They were always on page 2, and pages 1 and 3 were okay. Separating page 2 into its own TIFF with convert didn't change the problem.

statement_ocr_sample

Expected Behavior

All pages with text in the same format should be converted the same way.

Suggested Fix

No response

tesseract -v

Downloaded from the ppa:alex-p/tesseract-ocr5 repository tesseract 5.3.1 leptonica-1.79.0 libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 2.0.3) : libpng 1.6.37 : libtiff 4.1.0 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.1 Found AVX Found SSE4.1 Found OpenMP 201511 Found libarchive 3.4.0 zlib/1.2.11 liblzma/5.2.4 bz2lib/1.0.8 liblz4/1.9.2 libzstd/1.4.4 Found libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3

Also occurs with 4.0.1 downloaded from the Ubuntu 20.04 repository

Operating System

Ubuntu 20.04 Focal

Other Operating System

No response

uname -a

Linux delve 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Compiler

N/A: installed from .deb

CPU

processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 94 model name : Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz stepping : 3 microcode : 0xf0 cpu MHz : 1437.438 cache size : 8192 KB physical id : 0 siblings : 4 core id : 0 cpu cores : 4 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 22 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds bogomips : 6799.81 clflush size : 64 cache_alignment : 64 address sizes : 39 bits physical, 48 bits virtual power management:

Virtualization / Containers

None

Other Information

All Details are above.

RanTalbott avatar Jun 03 '23 04:06 RanTalbott

@RanTalbott I made a PDF 8.5in wide at 300 dpi with the image you shared output seems fine? can you share a pdf that fails?

$ pdfname=tesseract_example.pdf; tiffname=`basename ${pdfname}`.tiff; gs -q -dNOPAUSE -r288 -sDEVICE=tiffgray -sOutputFile=$tiffname $pdfname -c quit; tesseract $tiffname out --psm 3
$ cat out.txt
Trans. Post

Date Date Transaction Description Withdrawals Deposits BALANCE
Balance Forward $
01/01/20 01/01/20 Withdrawal Debit Card PINLESS DEBIT -3.03
TACO BELL #031725 SIERRA VISTA AZ
01/02/20 01/02/20 Recurring Withdrawal at ATM #032511 -43.54 |
VZWRLSS*PRPAY AUTOPAY 888-294-6804 FL

01/03/20 01/03/20 Deposit XXSOC SEC ; fen reno
TYPE: XXSOC SEC CO: XXSOC SEC

nezda avatar Dec 22 '23 14:12 nezda