public class TessBaseAPI extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
TessBaseAPI.PageIteratorLevel
Elements of the page hierarchy, used in
ResultIterator to provide
functions that operate on each level without having to have 5x as many
functions. |
static class |
TessBaseAPI.PageSegMode |
| Modifier and Type | Field and Description |
|---|---|
static int |
OEM_CUBE_ONLY
Run Cube only - better accuracy, but slower
|
static int |
OEM_DEFAULT
Default OCR engine mode.
|
static int |
OEM_TESSERACT_CUBE_COMBINED
Run both and combine results - best accuracy
|
static int |
OEM_TESSERACT_ONLY
Run Tesseract only - fastest
|
static String |
VAR_CHAR_BLACKLIST
Blacklist of characters to not recognize.
|
static String |
VAR_CHAR_WHITELIST
Whitelist of characters to recognize.
|
| Constructor and Description |
|---|
TessBaseAPI()
Constructs an instance of TessBaseAPI.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addPageToDocument(Pix imageToProcess,
String imageToWrite,
TessPdfRenderer tessPdfRenderer)
Appends sandwiched page to opened document (if any).
|
boolean |
beginDocument(TessPdfRenderer tessPdfRenderer)
Starts document creation
|
void |
clear()
Frees up recognition results and any stored image data, without actually
freeing any recognition data that would be time-consuming to reload.
|
void |
end()
Closes down tesseract and free up all memory.
|
boolean |
endDocument(TessPdfRenderer tessPdfRenderer)
Ends document creation
|
protected void |
finalize()
Called by the GC to clean up the native data that we set up when we
construct the object.
|
String |
getBoxText(int page)
The recognized text is returned as coded in the same format as a UTF8
box file used in training.
|
String |
getHOCRText(int page)
Make a HTML-formatted string with hOCR markup from the internal data
structures.
|
String |
getInitLanguagesAsString()
Returns the languages string used in the last valid initialization.
|
Pixa |
getRegions()
Returns the result of page layout analysis as a Pixa, in reading order.
|
ResultIterator |
getResultIterator() |
Pixa |
getStrips()
Returns the strips as a Pixa.
|
Pixa |
getTextlines()
Returns the textlines as a Pixa.
|
String |
getUTF8Text()
The recognized text is returned as a String which is coded as UTF8.
|
Pixa |
getWords()
Returns the word bounding boxes as a Pixa, in reading order.
|
boolean |
init(String datapath,
String language)
Initializes the Tesseract engine with a specified language model.
|
boolean |
init(String datapath,
String language,
int ocrEngineMode)
Initializes the Tesseract engine with the specified language model(s).
|
int |
meanConfidence()
Returns the mean confidence of text recognition.
|
void |
ReadConfigFile(String filename)
Read a "config" file containing a set of variable, value pairs.
|
void |
setDebug(boolean enabled)
Sets debug mode.
|
void |
setImage(android.graphics.Bitmap bmp)
Provides an image for Tesseract to recognize.
|
void |
setImage(byte[] imagedata,
int width,
int height,
int bpp,
int bpl)
Provides an image for Tesseract to recognize.
|
void |
setImage(File file)
Provides an image for Tesseract to recognize.
|
void |
setImage(Pix image)
Provides a Leptonica pix format image for Tesseract to recognize.
|
void |
setInputName(String name)
Set the name of the input file.
|
void |
setOutputName(String name)
Set the name of the output files.
|
void |
setPageSegMode(int mode)
Sets the page segmentation mode.
|
void |
setRectangle(int left,
int top,
int width,
int height)
Restricts recognition to a sub-rectangle of the image.
|
void |
setRectangle(android.graphics.Rect rect)
Restricts recognition to a sub-rectangle of the image.
|
boolean |
setVariable(String var,
String value)
Set the value of an internal "variable" (of either old or new types).
|
int[] |
wordConfidences()
Returns all word confidences (between 0 and 100) in an array.
|
public static final String VAR_CHAR_WHITELIST
public static final String VAR_CHAR_BLACKLIST
public static final int OEM_TESSERACT_ONLY
public static final int OEM_CUBE_ONLY
public static final int OEM_TESSERACT_CUBE_COMBINED
public static final int OEM_DEFAULT
protected void finalize()
throws Throwable
public boolean init(String datapath, String language)
true on success.
Instances are now mostly thread-safe and totally independent, but some global parameters remain. Basically it is safe to use multiple TessBaseAPIs in different threads in parallel, UNLESS you use SetVariable on some of the Params in classify and textord. If you do, then the effect will be to change it for all your instances.
The datapath must be the name of the parent directory of tessdata and
must end in / . Any name after the last / will be stripped. The language
is (usually) an ISO 639-3 string or null will default to eng.
It is entirely safe (and eventually will be efficient too) to call Init
multiple times on the same instance to change language, or just to reset
the classifier.
The language may be a string of the form [~]
WARNING: On changing languages, all Tesseract parameters are reset
back to their default values. (Which may vary between languages.)
If you have a rare need to set a Variable that controls initialization
for a second call to Init you should explicitly call End() and then use
SetVariable before Init. This is only a very rare use case, since there
are very few uses that require any parameters to be set before Init.
datapath - the parent directory of tessdata ending in a forward
slashlanguage - (optional) an ISO 639-3 string representing the language(s)true on successpublic boolean init(String datapath, String language, int ocrEngineMode)
true on success.datapath - the parent directory of tessdata ending in a forward
slashlanguage - (optional) an ISO 639-3 string representing the language(s)mode - the OCR engine mode to be settrue on successpublic String getInitLanguagesAsString()
public void clear()
public void end()
Once End() has been used, none of the other API functions may be used other than Init and anything declared above it in the class definition.
public boolean setVariable(String var, String value)
Example: setVariable(VAR_TESSEDIT_CHAR_BLACKLIST, "xyz"); to ignore x, y and z. * setVariable(VAR_BLN_NUMERICMODE, "1"); to set numeric-only mode. *
setVariable() may be used before open(), but settings will revert to defaults on close().
var - name of the variablevalue - value to setpublic void setPageSegMode(int mode)
mode - the page segmentation mode to setpublic void setDebug(boolean enabled)
enabled - true to enable debugging modepublic void setRectangle(android.graphics.Rect rect)
rect - the bounding rectanglepublic void setRectangle(int left,
int top,
int width,
int height)
left - the left boundtop - the right boundwidth - the width of the bounding boxheight - the height of the bounding boxpublic void setImage(File file)
file - absolute path to the image filepublic void setImage(android.graphics.Bitmap bmp)
bmp - bitmap representation of the imagepublic void setImage(Pix image)
image - Leptonica pix representation of the imagepublic void setImage(byte[] imagedata,
int width,
int height,
int bpp,
int bpl)
imagedata - byte representation of the imagewidth - image widthheight - image heightbpp - bytes per pixelbpl - bytes per linepublic String getUTF8Text()
public int meanConfidence()
public int[] wordConfidences()
public Pixa getRegions()
public Pixa getTextlines()
public Pixa getStrips()
public Pixa getWords()
public ResultIterator getResultIterator()
public String getHOCRText(int page)
page - is 0-based but will appear in the output as 1-based.public void setInputName(String name)
name - input file namepublic void setOutputName(String name)
name - output file namepublic void ReadConfigFile(String filename)
filename - the configuration filename, without pathpublic String getBoxText(int page)
page - is a 0-based page index that will appear in the box file.public boolean beginDocument(TessPdfRenderer tessPdfRenderer)
true on success. false on failurepublic boolean endDocument(TessPdfRenderer tessPdfRenderer)
true on success. false on failurepublic boolean addPageToDocument(Pix imageToProcess, String imageToWrite, TessPdfRenderer tessPdfRenderer)
imageToProcess - image which will be used for OCRimageToWrite - image which will be written into resulting documenttrue on success. false on failureCopyright © 2014. All rights reserved.