public class Tesseract extends Object implements ITesseract
TessAPI
, provides character
recognition support for common image formats, and multi-page TIFF images
beyond the uncompressed, binary TIFF format supported by Tesseract OCR
engine. The extended capabilities are provided by the
Java Advanced Imaging Image I/O Tools
.Ghost4J
, a
JNA
wrapper for GPL Ghostscript
, which should be
installed and included in system path..jar
files for jna
,
jai-imageio
, and ghost4j
) are in its compile and
run-time classpath
.ITesseract.RenderedFormat
htmlBeginTag, htmlEndTag
Constructor and Description |
---|
Tesseract() |
Modifier and Type | Method and Description |
---|---|
void |
createDocuments(String[] filenames,
String[] outputbases,
List<ITesseract.RenderedFormat> formats)
Creates documents.
|
void |
createDocuments(String filename,
String outputbase,
List<ITesseract.RenderedFormat> formats)
Creates documents for given renderer.
|
protected void |
dispose()
Releases all of the native resources used by this instance.
|
String |
doOCR(BufferedImage bi)
Performs OCR operation.
|
String |
doOCR(BufferedImage bi,
Rectangle rect)
Performs OCR operation.
|
String |
doOCR(File imageFile)
Performs OCR operation.
|
String |
doOCR(File imageFile,
Rectangle rect)
Performs OCR operation.
|
String |
doOCR(int xsize,
int ysize,
ByteBuffer buf,
Rectangle rect,
int bpp)
Performs OCR operation.
|
String |
doOCR(int xsize,
int ysize,
ByteBuffer buf,
String filename,
Rectangle rect,
int bpp)
Performs OCR operation.
|
String |
doOCR(List<IIOImage> imageList,
Rectangle rect)
Performs OCR operation.
|
String |
doOCR(List<IIOImage> imageList,
String filename,
Rectangle rect)
Performs OCR operation.
|
protected TessAPI |
getAPI()
Returns TessAPI object.
|
protected ITessAPI.TessBaseAPI |
getHandle()
Returns API handle.
|
static Tesseract |
getInstance()
Deprecated.
As of Release 2.0, use default constructor instead.
|
protected String |
getOCRText(String filename,
int pageNum)
Gets recognized text.
|
List<Rectangle> |
getSegmentedRegions(BufferedImage bi,
int pageIteratorLevel)
Gets segmented regions at specified page iterator level.
|
List<Word> |
getWords(BufferedImage bi,
int pageIteratorLevel)
Gets recognized words at specified page iterator level.
|
protected void |
init()
Initializes Tesseract engine.
|
void |
setConfigs(List<String> configs)
Sets configs to be passed to Tesseract's
Init method. |
void |
setDatapath(String datapath)
Sets path to
tessdata . |
void |
setHocr(boolean hocr)
Enables hocr output.
|
protected void |
setImage(int xsize,
int ysize,
ByteBuffer buf,
Rectangle rect,
int bpp)
Sets image to be processed.
|
protected void |
setImage(RenderedImage image,
Rectangle rect)
A wrapper for
setImage(int, int, ByteBuffer, Rectangle, int) . |
void |
setLanguage(String language)
Sets language for OCR.
|
void |
setOcrEngineMode(int ocrEngineMode)
Sets OCR engine mode.
|
void |
setPageSegMode(int mode)
Sets page segmentation mode.
|
void |
setTessVariable(String key,
String value)
Set the value of Tesseract's internal parameter.
|
protected void |
setTessVariables()
Sets Tesseract's internal parameters.
|
protected TessAPI getAPI()
protected ITessAPI.TessBaseAPI getHandle()
@Deprecated public static Tesseract getInstance()
public void setDatapath(String datapath)
tessdata
.setDatapath
in interface ITesseract
datapath
- the tessdata path to setpublic void setLanguage(String language)
setLanguage
in interface ITesseract
language
- the language code, which follows ISO 639-3 standard.public void setOcrEngineMode(int ocrEngineMode)
setOcrEngineMode
in interface ITesseract
ocrEngineMode
- the OcrEngineMode to setpublic void setPageSegMode(int mode)
setPageSegMode
in interface ITesseract
mode
- the page segmentation mode to setpublic void setHocr(boolean hocr)
hocr
- to enable or disable hocr outputpublic void setTessVariable(String key, String value)
setTessVariable
in interface ITesseract
key
- variable name, e.g., tessedit_create_hocr
,
tessedit_char_whitelist
, etc.value
- value for corresponding variable, e.g., "1", "0",
"0123456789", etc.public void setConfigs(List<String> configs)
Init
method.setConfigs
in interface ITesseract
configs
- list of config filenames, e.g., "digits", "bazaar",
"quiet"public String doOCR(File imageFile) throws TesseractException
doOCR
in interface ITesseract
imageFile
- an image fileTesseractException
public String doOCR(File imageFile, Rectangle rect) throws TesseractException
doOCR
in interface ITesseract
imageFile
- an image filerect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.TesseractException
public String doOCR(BufferedImage bi) throws TesseractException
doOCR
in interface ITesseract
bi
- a buffered imageTesseractException
public String doOCR(BufferedImage bi, Rectangle rect) throws TesseractException
doOCR
in interface ITesseract
bi
- a buffered imagerect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.TesseractException
public String doOCR(List<IIOImage> imageList, Rectangle rect) throws TesseractException
doOCR
in interface ITesseract
imageList
- a list of IIOImage
objectsrect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.TesseractException
public String doOCR(List<IIOImage> imageList, String filename, Rectangle rect) throws TesseractException
doOCR
in interface ITesseract
imageList
- a list of IIOImage
objectsfilename
- input file name. Needed only for training and reading a
UNLV zone file.rect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.TesseractException
public String doOCR(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp) throws TesseractException
SetImage
, (optionally)
SetRectangle
, and one or more of the Get*Text
functions.doOCR
in interface ITesseract
xsize
- width of imageysize
- height of imagebuf
- pixel datarect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.bpp
- bits per pixel, represents the bit depth of the image, with 1
for binary bitmap, 8 for gray, and 24 for color RGB.TesseractException
public String doOCR(int xsize, int ysize, ByteBuffer buf, String filename, Rectangle rect, int bpp) throws TesseractException
SetImage
, (optionally)
SetRectangle
, and one or more of the Get*Text
functions.doOCR
in interface ITesseract
xsize
- width of imageysize
- height of imagebuf
- pixel datafilename
- input file name. Needed only for training and reading a
UNLV zone file.rect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.bpp
- bits per pixel, represents the bit depth of the image, with 1
for binary bitmap, 8 for gray, and 24 for color RGB.TesseractException
protected void init()
protected void setTessVariables()
protected void setImage(RenderedImage image, Rectangle rect) throws IOException
setImage(int, int, ByteBuffer, Rectangle, int)
.image
- a rendered imagerect
- region of interestIOException
protected void setImage(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp)
xsize
- width of imageysize
- height of imagebuf
- pixel datarect
- the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or null
indicates
the whole image.bpp
- bits per pixel, represents the bit depth of the image, with 1
for binary bitmap, 8 for gray, and 24 for color RGB.protected String getOCRText(String filename, int pageNum)
filename
- input file name. Needed only for reading a UNLV zone
file.pageNum
- page number; needed for hocr paging.public void createDocuments(String filename, String outputbase, List<ITesseract.RenderedFormat> formats) throws TesseractException
createDocuments
in interface ITesseract
filename
- input imageoutputbase
- output filename without extensionformats
- types of rendererTesseractException
public void createDocuments(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats) throws TesseractException
createDocuments
in interface ITesseract
filenames
- array of input filesoutputbases
- array of output filenames without extensionformats
- types of rendererTesseractException
public List<Rectangle> getSegmentedRegions(BufferedImage bi, int pageIteratorLevel) throws TesseractException
getSegmentedRegions
in interface ITesseract
bi
- input imagepageIteratorLevel
- TessPageIteratorLevel enumRectangle
TesseractException
public List<Word> getWords(BufferedImage bi, int pageIteratorLevel)
getWords
in interface ITesseract
bi
- input imagepageIteratorLevel
- TessPageIteratorLevel enumWord
protected void dispose()
Copyright © 2017 Tess4J. All Rights Reserved.