之前一直在用tesseract_3.0.2,由于项目需求,必须用64位编译的tesseract库;于是转到4.0来了,编译器用的是vs2015,tesseract 3.0版本和4.0有一个区别就是TessResultRenderer类的使用,下面给大家贴出本人调用tesseract 4.0库的代码,如有问题还请大家多多指教!
#include <leptonica\allheaders.h>
#include <tesseract\baseapi.h>
#include <tesseract\renderer.h>
#include <iostream>
//环境要求: vs2015, tesseract 4.0
#pragma comment(lib, "libtesseract-4")
void main(int argc, char* argv[])
{
const char* outputbase = "out";
char* image = "1.jpg";
tesseract::TessBaseAPI api;
api.SetOutputName(outputbase);
if (api.Init("./", "chi_sim", tesseract::OEM_DEFAULT))
{
std::cout << "Could not initialize tesseract!" << std::endl;
}
tesseract::TessResultRenderer* renderer = new tesseract::TessTextRenderer(outputbase);
if (!api.ProcessPages(image, NULL, 0, renderer))
{
std::cout << "Error during processing!" << std::endl;
}
delete renderer;
system("pause");
}
关于 tesseract4.0的配置,在我的另外一篇博客里面,链接: