识别图片文字的基础函数

代码

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

你可能感兴趣的:(识别图片文字的基础函数)