----基于google tesseract-ocr-3.02版本;2012-12;
----Linux环境编译, 2014-12-01。
直接导入jar包,并把libs目录拷进项目即可使用。
ocr识别库下载
地址::
https://code.google.com/p/tesseract-ocr/downloads/list
调用示例程序:
public void testGetUTF8Text() {
// First, make sure the eng.traineddata file exists.
final String inputText = "hello";
final Bitmap bmp = getTextImage(inputText, 640, 480);
// Attempt to initialize the API.
final TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
baseApi.setImage(bmp);
// Ensure that the result is correct.
final String outputText = baseApi.getUTF8Text();
assertEquals("\"" + outputText + "\" != \"" + inputText + "\"", inputText, outputText);
// Ensure that getHOCRText() produced a result.
final String hOcr = baseApi.getHOCRText(0);
assertNotNull("HOCR result found", hOcr);
// Ensure getRegions() works.
final Pixa regions = baseApi.getRegions();
assertEquals("Found one region", regions.size(), 1);
// Ensure getWords() works.
final Pixa words = baseApi.getWords();
assertEquals("Found one word", words.size(), 1);
// Iterate through the results.
final ResultIterator iterator = baseApi.getResultIterator();
String lastUTF8Text;
float lastConfidence;
int[] lastBoundingBox;
int count = 0;
iterator.begin();
do {
lastUTF8Text = iterator.getUTF8Text(PageIteratorLevel.RIL_WORD);
lastConfidence = iterator.confidence(PageIteratorLevel.RIL_WORD);
lastBoundingBox = iterator.getBoundingBox(PageIteratorLevel.RIL_WORD);
count++;
} while (iterator.next(PageIteratorLevel.RIL_WORD));
// Attempt to shut down the API.
baseApi.end();
bmp.recycle();
}
1