Ubuntu tesseract
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
安装模型
sudo apt-get install tesseract-ocr-chi-sim
tesseract test.jpeg ./test -l chi-sim
#include <stdio.h> #include <tesseract/baseapi.h> #include <leptonica/allheaders.h> int main() { char *outText; tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); // Initialize tesseract-ocr with English, without specifying tessdata path if (api->Init(NULL, "eng+chi_sim")) { fprintf(stderr, "Could not initialize tesseract.\n"); exit(1); } // Open input image with leptonica library Pix *image = pixRead("./invoice_dialog.png"); api->SetImage(image); // Get OCR result outText = api->GetUTF8Text(); printf("OCR output:\n%s", outText); // Destroy used object and release memory api->End(); delete [] outText; pixDestroy(&image); return 0; }
g++ -o myprogram myprogram.cpp -llept -ltesseract
出错
/usr/bin/ld: /tmp/ccIl3vUD.o: undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3' //usr/lib/x86_64-linux-gnu/libstdc++.so.6: 无法添加符号: DSO missing from command line collect2: error: ld returned 1 exit status The terminal process terminated with exit code: 1
加入选项
g++ -o myprogram myprogram.cpp -llept -ltesseract -L/usr/lib/x86_64-linux-gnu -lstdc++
出错
fatal error: leptonica/allheaders.h: No such file or directory
sudo apt install libleptonica-dev
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步