asysbang

标题: 识别文字的基础函数 [打印本页]

作者: admin    时间: 2019-9-3 14:02
标题: 识别文字的基础函数
#代码

```
#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识别出大致的信息区域之后再识别

```






欢迎光临 asysbang (http://www.asysbang.com/) Powered by Discuz! X2.5