编译环境:Visual Studio 2010
所用类库版本:
zlib 1.2.7
jpegsr9
tiff-4.0.3
giflib-5.0.4
leptonica-1.69
tesseract-ocr3.0.2
下载地址http://pan.baidu.com/s/1c0pqvQg 密码rlib
测试代码
bool XYImage::RecognizeImage(const String &language /* = _T("eng") */,
const String &whitelist /* = _T("0123456789") */)
{
tesseract::TessBaseAPI api;
if (api.Init(GlobalizeString(AppBase::GetStartupPath()).toGBK(), GlobalizeString(language).toGBK(),
tesseract::OEM_DEFAULT) == -1)
{
assert(!"ocr init failed!");
return false;
}
api.SetVariable("classify_bln_numeric_mode", "1");
api.SetVariable("tessedit_char_whitelist", GlobalizeString(whitelist).toGBK());
auto pix = pixRead("F:\\1.bmp"); //把pixReadBmpStream函数从库里抄出来的, 可以实现加载内存图像
if (pix != nullptr)
{
api.SetImage(pix);
char *pUTF8 = api.GetUTF8Text();//UTF-8编码
if (pUTF8 != nullptr)
{
this->UTF8Text.Copy(pUTF8);
delete[] pUTF8;
}
pixDestroy(&pix);
return true;
} //if
return false;
}