Package net.sourceforge.tess4j
Class Tesseract
java.lang.Object
net.sourceforge.tess4j.Tesseract
- All Implemented Interfaces:
ITesseract
An object layer on top of
Support for PDF documents is available through
Any program that uses the library will need to ensure that the required libraries (the
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.Support for PDF documents is available through
PDFBox.Any program that uses the library will need to ensure that the required libraries (the
.jar files for jna and
jai-imageio) are in its compile and run-time
classpath.-
Nested Class Summary
Nested classes/interfaces inherited from interface net.sourceforge.tess4j.ITesseract
ITesseract.RenderedFormat -
Field Summary
Fields inherited from interface net.sourceforge.tess4j.ITesseract
DOCUMENT_TITLE, htmlBeginTag, htmlEndTag, PAGE_SEPARATOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateDocuments(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats) Creates documents for given renderer.voidcreateDocuments(String filename, String outputbase, List<ITesseract.RenderedFormat> formats) Creates documents for given renderer.createDocumentsWithResults(BufferedImage[] bis, String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) Creates documents with OCR results for given renderers at specified page iterator level.createDocumentsWithResults(BufferedImage bi, String filename, String outputbase, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) Creates documents with OCR result for given renderers at specified page iterator level.createDocumentsWithResults(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) Creates documents with OCR results for given renderers at specified page iterator level.createDocumentsWithResults(String filename, String outputbase, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) Creates documents with OCR result for given renderers at specified page iterator level.protected voiddispose()Releases all of the native resources used by this instance.doOCR(int xsize, int ysize, ByteBuffer buf, int bpp, String filename, List<Rectangle> rects) Performs OCR operation.doOCR(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp) Deprecated.doOCR(int xsize, int ysize, ByteBuffer buf, String filename, Rectangle rect, int bpp) Deprecated.doOCR(BufferedImage bi) Performs OCR operation.doOCR(BufferedImage bi, Rectangle rect) Deprecated.doOCR(BufferedImage bi, String filename, List<Rectangle> rects) Performs OCR operation.Performs OCR operation.Deprecated.Performs OCR operation.Deprecated.Deprecated.Performs OCR operation.protected TessAPIgetAPI()Returns TessAPI object.protected ITessAPI.TessBaseAPIReturns API handle.protected StringgetOCRText(String filename, int pageNum) Gets recognized text.getSegmentedRegions(BufferedImage bi, int pageIteratorLevel) Gets segmented regions at specified page iterator level.getWords(BufferedImage bi, int pageIteratorLevel) Gets recognized words at specified page iterator level.getWords(List<BufferedImage> biList, int pageIteratorLevel) Gets recognized words at specified page iterator level.protected voidinit()Initializes Tesseract engine.voidsetConfigs(List<String> configs) Sets configs to be passed to Tesseract'sInitmethod.voidsetDatapath(String datapath) Sets path totessdata.protected voidsetImage(int xsize, int ysize, ByteBuffer buf, int bpp) Sets image to be processed.protected voidsetImage(RenderedImage image) A wrapper forsetImage(int, int, ByteBuffer, int).voidsetLanguage(String language) Sets language for OCR.voidsetOcrEngineMode(int ocrEngineMode) Sets OCR engine mode.voidsetPageSegMode(int mode) Sets page segmentation mode.protected voidSets region of interest.voidsetTessVariable(String key, String value) Deprecated.voidsetVariable(String key, String value) Set the value of Tesseract's internal parameter.protected voidSets Tesseract's internal parameters.
-
Constructor Details
-
Tesseract
public Tesseract()
-
-
Method Details
-
getAPI
Returns TessAPI object.- Returns:
- api
-
getHandle
Returns API handle.- Returns:
- handle
-
setDatapath
Sets path totessdata.- Specified by:
setDatapathin interfaceITesseract- Parameters:
datapath- the tessdata path to set
-
setLanguage
Sets language for OCR.- Specified by:
setLanguagein interfaceITesseract- Parameters:
language- the language code, which follows ISO 639-3 standard.
-
setOcrEngineMode
public void setOcrEngineMode(int ocrEngineMode) Sets OCR engine mode.- Specified by:
setOcrEngineModein interfaceITesseract- Parameters:
ocrEngineMode- the OcrEngineMode to set
-
setPageSegMode
public void setPageSegMode(int mode) Sets page segmentation mode.- Specified by:
setPageSegModein interfaceITesseract- Parameters:
mode- the page segmentation mode to set
-
setTessVariable
Deprecated.UsesetVariable(java.lang.String,java.lang.String)instead.Set the value of Tesseract's internal parameter.- Specified by:
setTessVariablein interfaceITesseract- Parameters:
key- variable name, e.g.,tessedit_create_hocr,tessedit_char_whitelist, etc.value- value for corresponding variable, e.g., "1", "0", "0123456789", etc.
-
setVariable
Set the value of Tesseract's internal parameter.- Specified by:
setVariablein interfaceITesseract- Parameters:
key- variable name, e.g.,tessedit_create_hocr,tessedit_char_whitelist, etc.value- value for corresponding variable, e.g., "1", "0", "0123456789", etc.
-
setConfigs
Sets configs to be passed to Tesseract'sInitmethod.- Specified by:
setConfigsin interfaceITesseract- Parameters:
configs- list of config filenames, e.g., "digits", "bazaar", "quiet"
-
doOCR
Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
imageFile- an image file- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
Deprecated.Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
inputFile- an image filerect- the bounding rectangle defines the region of the image to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
inputFile- an image filerects- list of the bounding rectangles defines the regions of the image to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
bi- a buffered image- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
Deprecated.Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
bi- a buffered imagerect- the bounding rectangle defines the region of the image to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
public String doOCR(BufferedImage bi, String filename, List<Rectangle> rects) throws TesseractException Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
bi- a buffered imagefilename- input file name. Needed only for training and reading a UNLV zone file.rects- list of the bounding rectangles defines the regions of the image to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
Deprecated.Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
imageList- a list ofIIOImageobjectsrect- the bounding rectangle defines the region of the image to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
@Deprecated public String doOCR(List<IIOImage> imageList, String filename, Rectangle rect) throws TesseractException Deprecated.Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
imageList- a list ofIIOImageobjectsfilename- 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 ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
public String doOCR(List<IIOImage> imageList, String filename, List<List<Rectangle>> roiss) throws TesseractException Performs OCR operation.- Specified by:
doOCRin interfaceITesseract- Parameters:
imageList- a list ofIIOImageobjectsfilename- input file name. Needed only for training and reading a UNLV zone file.roiss- list of list of the bounding rectangles defines the regions of the images to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
@Deprecated public String doOCR(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp) throws TesseractException Deprecated.Performs OCR operation. UseSetImage, (optionally)SetRectangle, and one or more of theGet*Textfunctions.- Specified by:
doOCRin interfaceITesseract- Parameters:
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 ornullindicates 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.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
@Deprecated public String doOCR(int xsize, int ysize, ByteBuffer buf, String filename, Rectangle rect, int bpp) throws TesseractException Deprecated.Performs OCR operation. UseSetImage, (optionally)SetRectangle, and one or more of theGet*Textfunctions.- Specified by:
doOCRin interfaceITesseract- Parameters:
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 ornullindicates 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.- Returns:
- the recognized text
- Throws:
TesseractException
-
doOCR
public String doOCR(int xsize, int ysize, ByteBuffer buf, int bpp, String filename, List<Rectangle> rects) throws TesseractException Performs OCR operation. UseSetImage, (optionally)SetRectangle, and one or more of theGet*Textfunctions.- Specified by:
doOCRin interfaceITesseract- Parameters:
xsize- width of imageysize- height of imagebuf- pixel databpp- bits per pixel, represents the bit depth of the image, with 1 for binary bitmap, 8 for gray, and 24 for color RGB.filename- input file name. Needed only for training and reading a UNLV zone file.rects- list of the bounding rectangle defines the regions of the image to be recognized. A rectangle of zero dimension ornullindicates the whole image.- Returns:
- the recognized text
- Throws:
TesseractException
-
init
protected void init()Initializes Tesseract engine. -
setVariables
protected void setVariables()Sets Tesseract's internal parameters. -
setImage
A wrapper forsetImage(int, int, ByteBuffer, int).- Parameters:
image- a rendered image- Throws:
IOException
-
setImage
Sets image to be processed.- Parameters:
xsize- width of imageysize- height of imagebuf- pixel databpp- bits per pixel, represents the bit depth of the image, with 1 for binary bitmap, 8 for gray, and 24 for color RGB.
-
setROI
Sets region of interest.- Parameters:
rect- region of interest
-
getOCRText
Gets recognized text.- Parameters:
filename- input file name. Needed only for reading a UNLV zone file.pageNum- page number; needed for hocr paging.- Returns:
- the recognized text
-
createDocuments
public void createDocuments(String filename, String outputbase, List<ITesseract.RenderedFormat> formats) throws TesseractException Creates documents for given renderer.- Specified by:
createDocumentsin interfaceITesseract- Parameters:
filename- input imageoutputbase- output filename without extensionformats- types of renderer- Throws:
TesseractException
-
createDocuments
public void createDocuments(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats) throws TesseractException Creates documents for given renderer.- Specified by:
createDocumentsin interfaceITesseract- Parameters:
filenames- array of input filesoutputbases- array of output filenames without extensionformats- types of renderer- Throws:
TesseractException
-
getSegmentedRegions
public List<Rectangle> getSegmentedRegions(BufferedImage bi, int pageIteratorLevel) throws TesseractException Gets segmented regions at specified page iterator level.- Specified by:
getSegmentedRegionsin interfaceITesseract- Parameters:
bi- input buffered imagepageIteratorLevel- TessPageIteratorLevel enum- Returns:
- list of
Rectangle - Throws:
TesseractException
-
getWords
Gets recognized words at specified page iterator level.- Specified by:
getWordsin interfaceITesseract- Parameters:
bi- input buffered imagepageIteratorLevel- TessPageIteratorLevel enum- Returns:
- list of
Word
-
getWords
Gets recognized words at specified page iterator level.- Specified by:
getWordsin interfaceITesseract- Parameters:
biList- list of input buffered imagespageIteratorLevel- TessPageIteratorLevel enum- Returns:
- list of
Word
-
createDocumentsWithResults
public OCRResult createDocumentsWithResults(BufferedImage bi, String filename, String outputbase, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) throws TesseractException Creates documents with OCR result for given renderers at specified page iterator level.- Specified by:
createDocumentsWithResultsin interfaceITesseract- Parameters:
bi- input buffered imagefilename- filename (optional)outputbase- output filenames without extensionformats- types of rendererpageIteratorLevel- TessPageIteratorLevel enum- Returns:
- OCR result
- Throws:
TesseractException
-
createDocumentsWithResults
public List<OCRResult> createDocumentsWithResults(BufferedImage[] bis, String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) throws TesseractException Creates documents with OCR results for given renderers at specified page iterator level.- Specified by:
createDocumentsWithResultsin interfaceITesseract- Parameters:
bis- array of input buffered imagesfilenames- array of filenamesoutputbases- array of output filenames without extensionformats- types of rendererpageIteratorLevel- TessPageIteratorLevel enum- Returns:
- list of OCR results
- Throws:
TesseractException
-
createDocumentsWithResults
public OCRResult createDocumentsWithResults(String filename, String outputbase, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) throws TesseractException Creates documents with OCR result for given renderers at specified page iterator level.- Specified by:
createDocumentsWithResultsin interfaceITesseract- Parameters:
filename- input fileoutputbase- output filenames without extensionformats- types of rendererpageIteratorLevel- TessPageIteratorLevel enum- Returns:
- OCR result
- Throws:
TesseractException
-
createDocumentsWithResults
public List<OCRResult> createDocumentsWithResults(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) throws TesseractException Creates documents with OCR results for given renderers at specified page iterator level.- Specified by:
createDocumentsWithResultsin interfaceITesseract- Parameters:
filenames- array of input filesoutputbases- array of output filenames without extensionformats- types of rendererpageIteratorLevel- TessPageIteratorLevel enum- Returns:
- list of OCR results
- Throws:
TesseractException
-
dispose
protected void dispose()Releases all of the native resources used by this instance.
-
setVariable(java.lang.String,java.lang.String)instead.