public class TesseractOCREngine extends OCREngine
We have added direct tesseract.exe support for findTextRectFromImage(). The output format of this file is different and uses a different coordinate system then the SAFS DLL, but it provides greater text recognition accuracy for better matching and locating text.
If a version other than Tesseract 2.04 is installed, the environment variable TESSDATA_VERSION
should be set. Ex: TESSDATA_VERSION=3.4.4
We don't know of any other means to deduce the version of tesseract installed.
tessFileParser
,
ReverseRectangle
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LANG_CHN
"chi"
|
static java.lang.String |
LANG_ENG
"eng"
|
static java.lang.String |
LANG_FRA
"fra"
|
static java.lang.String |
LANG_JPN
"jpn"
|
static java.lang.String |
LANG_KOR
"kor"
|
static java.util.HashMap<java.lang.String,java.lang.String> |
languages |
static java.lang.String |
TESSERACT_VERSION
Coded default to "2.04"
Static initializers look for System Environment variable "TESSDATA_VERSION" to change this.
|
static int |
TEXT_FIND_MODE
Set to desired mode for locating coordinates of text.
TEXT_FIND_TESSDLL_MODE was the original mechanism used. |
static int |
TEXT_FIND_TESSDLL_MODE
Mode value to use SAFSTESSDLL wrapper to locate coordinates of image text.
|
static int |
TEXT_FIND_TESSEXE_MODE
Mode value to use tesseract.exe directory to locate coordinates of image text.
|
static java.lang.String |
TMP_DIR_PROPERTY
"java.io.tmpdir"
|
static java.lang.String |
TMP_TEXT_COOR_OUTPUT
"~tempcoor.txt"
|
static java.lang.String |
TMP_TEXT_COOR_ROOT
"~tempcoor"
|
static java.lang.String |
TMP_TEXT_OUTPUT
"~temp"
|
static java.lang.String |
TMP_TIF_SCALEDED
"~temp.tif"
|
defaultZoomScale, OCR_DEFAULT_ENGINE_CLAZZ, OCR_DEFAULT_ENGINE_KEY, OCR_G_ENGINE_CLAZZ, OCR_G_ENGINE_KEY, OCR_T_ENGINE_CLAZZ, OCR_T_ENGINE_KEY, STAF_OCR_ENGINE_VAR_NAME, STAF_OCR_LANGUAGE_ID_VAR_NAME
Constructor and Description |
---|
TesseractOCREngine() |
Modifier and Type | Method and Description |
---|---|
java.awt.Rectangle |
findTextRectFromImage(java.lang.String searchtext,
int index,
java.awt.image.BufferedImage image,
java.lang.String stdlangId,
java.awt.Rectangle subarea,
float zoom)
Find text from BufferedImage, and return its area in the BufferedImage.
|
protected java.lang.String |
getSelfDefinedLangId(java.lang.String StdlangId)
Override its super.
|
java.lang.String |
imageToText(java.awt.image.BufferedImage image,
java.lang.String langId,
java.awt.Rectangle subarea,
float zoom)
Convert buffered image to text using OCR technology.
|
static void |
main(java.lang.String[] args)
Can be used to unit test.
|
getdefaultZoomScale, getOCREngine, getOCREngineKey, getOCRLanguageCode, imageToText, runCommandLine, setdefaultZoomScale, setOCREngineKey, setOCRLanguageCode, storedImageToText, storedImageToText, zoomImageWithType
public static final java.lang.String LANG_ENG
public static final java.lang.String LANG_CHN
public static final java.lang.String LANG_JPN
public static final java.lang.String LANG_KOR
public static final java.lang.String LANG_FRA
public static java.lang.String TMP_DIR_PROPERTY
public static java.lang.String TMP_TIF_SCALEDED
public static java.lang.String TMP_TEXT_OUTPUT
public static java.lang.String TMP_TEXT_COOR_ROOT
public static java.lang.String TMP_TEXT_COOR_OUTPUT
public static java.lang.String TESSERACT_VERSION
public static java.util.HashMap<java.lang.String,java.lang.String> languages
public static final int TEXT_FIND_TESSDLL_MODE
public static final int TEXT_FIND_TESSEXE_MODE
public static int TEXT_FIND_MODE
Possible values: TEXT_FIND_TESSDLL_MODE, and the default TEXT_FIND_TESSEXE_MODE.
public java.lang.String imageToText(java.awt.image.BufferedImage image, java.lang.String langId, java.awt.Rectangle subarea, float zoom) throws SAFSException
OCREngine
imageToText
in class OCREngine
SAFSException
- if meets any Exceptionprotected java.lang.String getSelfDefinedLangId(java.lang.String StdlangId)
getSelfDefinedLangId
in class OCREngine
langId,
- standard language codepublic java.awt.Rectangle findTextRectFromImage(java.lang.String searchtext, int index, java.awt.image.BufferedImage image, java.lang.String stdlangId, java.awt.Rectangle subarea, float zoom) throws SAFSException
TESSDLL Mode: Two files SafsTessdll.exe and tessdll.dll will be used. Two files will be output in current user's Temp directory. 1. ~temp.tif scaled image 2. ~tempcoor.txt text file storing detected text and their coordinates. Rectangle coordinates 0,0 relative to TOP-LEFT corner of search area.
TESSEXE Mode: tesseract.exe will be used. Two files will be output in current user's Temp directory. 1. ~temp.tif scaled image 2. ~tempcoor.txt text file storing detected text and their coordinates. ReverseRectangle coordinates 0,0 relative to BOTTOM-LEFT corner of search area.
findTextRectFromImage
in class OCREngine
searchtext,
- text for which to searchindex,
- starts from 1, specifies to find the Nth instance of searchText.image,
- source BufferedImage for detectingstdlangId,
- standard language id with which TOCR intends to detect. Refer to Locale.ENGLISH.getLanguage().subarea
- zoom
- SAFSException
#TEXT_FIND_MODE}
,
ReverseRectangle
public static void main(java.lang.String[] args)
java org.safs.tools.ocr.tesseract.TesseractOCREngine imageFile [-z zoom] [-l lang] [-t text]
imageFile - path to screen captured image to process.
zoom - zoom level to use for OCR. Defaults to 1.9.
lang - locale to use for OCR. Ex: "en"
text - text to locate in image.
args
- -- up to 7 array items: imageFile [-z zoom] [-l lang] [-t text]
imageFile - (required) path to screen captured image to process.Copyright © SAS Institute. All Rights Reserved.