New Tool Radar

AI PDF

How to Set the DPI for a Tesseract OCR Run and Check the Recognised Text Is Complete

Tell Tesseract the scan resolution with the DPI option, then check no lines are missing from the output.

Schematic with three steps: Note the scan resolution; Run OCR with the DPI set; Check completeness line by line.

Tesseract needs to know the resolution of the input image to size its character recognition correctly, and the –dpi option sets it. A scan whose resolution is unknown or wrongly guessed can lose lines or misread small text, so set the DPI explicitly and check the output is complete.

What you need

  • Tesseract installed
  • A scanned page image with a known scan resolution
  • The page count and the first and last lines of the page

Step 1: Note the scan resolution

Check the resolution the page was scanned at, and confirm it in the image properties if you are unsure.

Step 2: Run OCR with the DPI set

Run Tesseract with –dpi and the resolution number, for example tesseract page.png output –dpi 300, and open the output text.

Step 3: Check completeness line by line

Compare the output with the page image: count the lines, and confirm the first and last lines of the page are present and readable.

Worked example: synthetic DPI check on a scanned invoice

The table below is a synthetic example. It shows the expected result of checking OCR completeness; no OCR was run.

Check No DPI set DPI 300 set
Lines in output 18 of 22 22 of 22
First line present Yes Yes
Last line present No Yes
Total amount correct No Yes

Expected result (UNTESTED). without a DPI setting only 18 of 22 lines appear and the total is wrong, while with DPI 300 set all 22 lines appear and the total is correct. Set the DPI for every scan run. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Accuracy depends on image quality, language, page segmentation, trained data and the engine used.
  • Very small text needs a higher resolution scan; raising the DPI value alone cannot add detail the scan lacks.
  • Tesseract accepts image files directly; for a PDF, convert pages to images first or use OCRmyPDF.

Sources

See all