Package org.apache.tika.parser.ocr
Class TesseractOCRConfig
- java.lang.Object
-
- org.apache.tika.parser.ocr.TesseractOCRConfig
-
- All Implemented Interfaces:
java.io.Serializable
public class TesseractOCRConfig extends java.lang.Object implements java.io.Serializable
Configuration for TesseractOCRParser.This allows to enable TesseractOCRParser and set its parameters:
TesseractOCRConfig config = new TesseractOCRConfig();
config.setTesseractPath(tesseractFolder);
parseContext.set(TesseractOCRConfig.class, config);
Parameters can also be set by either editing the existing TesseractOCRConfig.properties file in, tika-parser/src/main/resources/org/apache/tika/parser/ocr, or overriding it by creating your own and placing it in the package org/apache/tika/parser/ocr on the classpath.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TesseractOCRConfig.OUTPUT_TYPE
-
Constructor Summary
Constructors Constructor Description TesseractOCRConfig()
Default contructor.TesseractOCRConfig(java.io.InputStream is)
Loads properties from InputStream and then tries to close InputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOtherTesseractConfig(java.lang.String key, java.lang.String value)
Add a key-value pair to pass to Tesseract using its -c command line option.boolean
getApplyRotation()
java.lang.String
getColorspace()
int
getDensity()
int
getDepth()
java.lang.String
getFilter()
java.lang.String
getImageMagickPath()
java.lang.String
getLanguage()
long
getMaxFileSizeToOcr()
long
getMinFileSizeToOcr()
java.util.Map<java.lang.String,java.lang.String>
getOtherTesseractConfig()
TesseractOCRConfig.OUTPUT_TYPE
getOutputType()
java.lang.String
getPageSegMode()
java.lang.String
getPageSeparator()
boolean
getPreserveInterwordSpacing()
int
getResize()
java.lang.String
getTessdataPath()
java.lang.String
getTesseractPath()
int
getTimeout()
int
isEnableImageProcessing()
void
setApplyRotation(boolean applyRotation)
Sets whether or not a rotation value should be calculated and passed to ImageMagick.void
setColorspace(java.lang.String colorspace)
void
setDensity(int density)
void
setDepth(int depth)
void
setEnableImageProcessing(int enableImageProcessing)
Set the value to true if processing is to be enabled.void
setFilter(java.lang.String filter)
void
setImageMagickPath(java.lang.String imageMagickPath)
Set the path to the ImageMagick executable directory, needed if it is not on system path.void
setLanguage(java.lang.String language)
Set tesseract language dictionary to be used.void
setMaxFileSizeToOcr(long maxFileSizeToOcr)
Set maximum file size to submit file to ocr.void
setMinFileSizeToOcr(long minFileSizeToOcr)
Set minimum file size to submit file to ocr.void
setOutputType(java.lang.String outputType)
void
setOutputType(TesseractOCRConfig.OUTPUT_TYPE outputType)
Set output type from ocr process.void
setPageSegMode(java.lang.String pageSegMode)
Set tesseract page segmentation mode.void
setPageSeparator(java.lang.String pageSeparator)
The page separator to use in plain text output.void
setPreserveInterwordSpacing(boolean preserveInterwordSpacing)
Whether or not to maintain interword spacing.void
setResize(int resize)
void
setTessdataPath(java.lang.String tessdataPath)
Set the path to the 'tessdata' folder, which contains language files and config files.void
setTesseractPath(java.lang.String tesseractPath)
Set the path to the Tesseract executable's directory, needed if it is not on system path.void
setTimeout(int timeout)
Set maximum time (seconds) to wait for the ocring process to terminate.void
setTrustedPageSeparator(java.lang.String pageSeparator)
Same assetPageSeparator(String)
but does not perform any checks on the string.
-
-
-
Constructor Detail
-
TesseractOCRConfig
public TesseractOCRConfig()
Default contructor.
-
TesseractOCRConfig
public TesseractOCRConfig(java.io.InputStream is)
Loads properties from InputStream and then tries to close InputStream. If there is an IOException, this silently swallows the exception and goes back to the default.- Parameters:
is
-
-
-
Method Detail
-
getTesseractPath
public java.lang.String getTesseractPath()
- See Also:
setTesseractPath(String tesseractPath)
-
setTesseractPath
public void setTesseractPath(java.lang.String tesseractPath)
Set the path to the Tesseract executable's directory, needed if it is not on system path.Note that if you set this value, it is highly recommended that you also set the path to the 'tessdata' folder using
setTessdataPath(java.lang.String)
.
-
getTessdataPath
public java.lang.String getTessdataPath()
- See Also:
setTessdataPath(String tessdataPath)
-
setTessdataPath
public void setTessdataPath(java.lang.String tessdataPath)
Set the path to the 'tessdata' folder, which contains language files and config files. In some cases (such as on Windows), this folder is found in the Tesseract installation, but in other cases (such as when Tesseract is built from source), it may be located elsewhere.
-
getLanguage
public java.lang.String getLanguage()
- See Also:
setLanguage(String language)
-
setLanguage
public void setLanguage(java.lang.String language)
Set tesseract language dictionary to be used. Default is "eng". Multiple languages may be specified, separated by plus characters. e.g. "chi_tra+chi_sim"
-
getPageSegMode
public java.lang.String getPageSegMode()
- See Also:
setPageSegMode(String pageSegMode)
-
setPageSegMode
public void setPageSegMode(java.lang.String pageSegMode)
Set tesseract page segmentation mode. Default is 1 = Automatic page segmentation with OSD (Orientation and Script Detection)
-
getPageSeparator
public java.lang.String getPageSeparator()
- See Also:
setPageSeparator(String pageSeparator)
-
setPageSeparator
public void setPageSeparator(java.lang.String pageSeparator)
The page separator to use in plain text output. This corresponds to Tesseract's page_separator config option. The default here is the empty string (i.e. no page separators). Note that this is also the default in Tesseract 3.x, but in Tesseract 4.0 the default is to use the form feed control character. We are overriding Tesseract 4.0's default here.- Parameters:
pageSeparator
-
-
setTrustedPageSeparator
public void setTrustedPageSeparator(java.lang.String pageSeparator)
Same assetPageSeparator(String)
but does not perform any checks on the string.- Parameters:
pageSeparator
-
-
setPreserveInterwordSpacing
public void setPreserveInterwordSpacing(boolean preserveInterwordSpacing)
Whether or not to maintain interword spacing. Default isfalse
.- Parameters:
preserveInterwordSpacing
-
-
getPreserveInterwordSpacing
public boolean getPreserveInterwordSpacing()
- Returns:
- whether or not to maintain interword spacing.
-
getMinFileSizeToOcr
public long getMinFileSizeToOcr()
-
setMinFileSizeToOcr
public void setMinFileSizeToOcr(long minFileSizeToOcr)
Set minimum file size to submit file to ocr. Default is 0.
-
getMaxFileSizeToOcr
public long getMaxFileSizeToOcr()
-
setMaxFileSizeToOcr
public void setMaxFileSizeToOcr(long maxFileSizeToOcr)
Set maximum file size to submit file to ocr. Default is Integer.MAX_VALUE.
-
setTimeout
public void setTimeout(int timeout)
Set maximum time (seconds) to wait for the ocring process to terminate. Default value is 120s.
-
getTimeout
public int getTimeout()
- Returns:
- timeout value for Tesseract
- See Also:
setTimeout(int timeout)
-
setOutputType
public void setOutputType(TesseractOCRConfig.OUTPUT_TYPE outputType)
Set output type from ocr process. Default is "txt", but can be "hocr". Default value isTesseractOCRConfig.OUTPUT_TYPE.TXT
.
-
setOutputType
public void setOutputType(java.lang.String outputType)
-
getOutputType
public TesseractOCRConfig.OUTPUT_TYPE getOutputType()
- See Also:
setOutputType(OUTPUT_TYPE outputType)
-
isEnableImageProcessing
public int isEnableImageProcessing()
- Returns:
- image processing is enabled or not
- See Also:
setEnableImageProcessing(int)
-
setEnableImageProcessing
public void setEnableImageProcessing(int enableImageProcessing)
Set the value to true if processing is to be enabled. Default value is false.
-
getDensity
public int getDensity()
- Returns:
- the density
-
setDensity
public void setDensity(int density)
- Parameters:
density
- the density to set. Valid range of values is 150-1200. Default value is 300.
-
getDepth
public int getDepth()
- Returns:
- the depth
-
setDepth
public void setDepth(int depth)
- Parameters:
depth
- the depth to set. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096. Default value is 4.
-
getColorspace
public java.lang.String getColorspace()
- Returns:
- the colorspace
-
setColorspace
public void setColorspace(java.lang.String colorspace)
- Parameters:
colorspace
- the colorspace to set Deafult value is gray.
-
getFilter
public java.lang.String getFilter()
- Returns:
- the filter
-
setFilter
public void setFilter(java.lang.String filter)
- Parameters:
filter
- the filter to set. Valid values are point, hermite, cubic, box, gaussian, catrom, triangle, quadratic and mitchell. Default value is triangle.
-
getResize
public int getResize()
- Returns:
- the resize
-
setResize
public void setResize(int resize)
- Parameters:
resize
- the resize to set. Valid range of values is 100-900. Default value is 900.
-
getImageMagickPath
public java.lang.String getImageMagickPath()
- Returns:
- path to ImageMagick executable directory.
- See Also:
setImageMagickPath(String imageMagickPath)
-
setImageMagickPath
public void setImageMagickPath(java.lang.String imageMagickPath)
Set the path to the ImageMagick executable directory, needed if it is not on system path.- Parameters:
imageMagickPath
- to ImageMagick executable directory.
-
getApplyRotation
public boolean getApplyRotation()
- Returns:
- Whether or not a rotation value should be calculated and passed to ImageMagick before performing OCR. (Requires that Python is installed).
-
setApplyRotation
public void setApplyRotation(boolean applyRotation)
Sets whether or not a rotation value should be calculated and passed to ImageMagick.- Parameters:
applyRotation
- to calculate and apply rotation, false to skip. Default is false, true required Python installed.
-
getOtherTesseractConfig
public java.util.Map<java.lang.String,java.lang.String> getOtherTesseractConfig()
- See Also:
addOtherTesseractConfig(String, String)
-
addOtherTesseractConfig
public void addOtherTesseractConfig(java.lang.String key, java.lang.String value)
Add a key-value pair to pass to Tesseract using its -c command line option. To see the possible options, run tesseract --print-parameters. You may also add these parameters in TesseractOCRConfig.properties; any key-value pair in the properties file where the key contains an underscore is passed directly to Tesseract.- Parameters:
key
-value
-
-
-