识别图片文字的基础函数
2018-12-18 本文已影响0人
King_Karl
代码
#include "iostream"
#include "tesseract/baseapi.h"
#include "leptonica/allheaders.h"
using namespace std;
int main () {
char *outText;
cout << "======>>> start" << '\n';
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
if (api->Init(NULL, "chi_sim")) {
cout << "======>>> init error" << '\n';
return -1;
} else {
cout << "======>>> init ok" << '\n';
}
Pix *image = pixRead("test.tif");
api->SetImage(image);
outText = api->GetUTF8Text();
cout << "======>>> get text : " << outText << '\n';
api-> End();
delete [] outText;
return 0;
}
编译
g++ -o hello hell.cpp -llept -ltesseract -std=c++11
验证
======>>> start
======>>> init ok
======>>> get text : 启 动 BALL
其他
api->SetRectangle(left, top, width, height);
可以设置需要识别的区域
基于opencv识别出大致的信息区域之后再识别