Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set tessedit_write_images in python-tesseract?

I'm trying to set tessedit_write_images but can't seem to do it, i can't see the tessinput.tif anywhere

i'm doing:

import tesseract

api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_TESSERACT_ONLY)
api.SetPageSegMode(tesseract.PSM_AUTO_OSD)
api.SetVariable("tessedit_write_images", "T")

but i've tried with "True", "1", and some more variations, doesn't seem to work at all.

Any help?

like image 978
tiagosilva Avatar asked Jul 22 '15 10:07

tiagosilva


People also ask

How do you use Tesseract in Python?

Gain hands-on experience using Tesseract to OCR an image. Learn how to import the pytesseract package into your Python scripts. Use OpenCV to load an input image from disk. Pass the image into the Tesseract OCR engine via the pytesseract library.

What is OEM in Tesseract?

The --oem argument, or OCR Engine Mode, controls the type of algorithm used by Tesseract. The --psm controls the automatic Page Segmentation Mode used by Tesseract.

What is Tesseract page segmentation mode?

Tesseract attempts to apply automatic page segmentation methods, but due to the fact that there is no actual “page” of text, the default --psm 3 fails and returns an empty string. We can resolve the matter by treating the input image as a single character via --psm 10 : $ tesseract number.png stdout --psm 10 2.


1 Answers

tessedit_write_images is checked only once in Tesseract's source code (by TessBaseAPI::ProcessPage(), see here).

So you have two ways:

  1. Call api.GetThresholdedImage(), and the returned image is what will be saved if you set the variable and call ProcessPage.
  2. Just call api.ProcessPage(), and it will see the variable and output the tif.
like image 99
cortex42 Avatar answered Sep 21 '22 14:09

cortex42