Tesseract无法加载任何语言问题

发布于 2025-02-10 00:50:04 字数 1389 浏览 2 评论 0原文

我在互联网上搜索,然后尝试将我的tessdata_prefix更改为导出tessdata_prefix =/usr/local/local/share/tessdata或... share/tessract-ocr/4.00或5/tessdata和tessdata and tesseract/tessdata* 。我在所有这些位置都有Eng.TrainedData文件。但是我仍会遇到此错误,我尝试从Github更改训练的数据文件。但是我仍然遇到这个错误。

这是我的代码

#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(){
cv::Mat image;
string outText;
image = cv::imread("text.png",cv::IMREAD_COLOR);

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng", tesseract::OEM_LSTM_ONLY);
api->SetPageSegMode(tesseract::PSM_AUTO);
api->SetImage(image.data, image.cols, image.rows, 3, image.step);
outText = string(api->GetUTF8Text());
cout << outText;
api->End();
    
}

我的makefile,

CC = g++
PROJECT = main
SRC = main.cpp
LIBS = `pkg-config --cflags --libs opencv4 tesseract`
$(PROJECT) : $(SRC)
    $(CC) $(SRC) $(LIBS) -o $(PROJECT) 

这是错误消息

Error opening data file /usr/local/share/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
Estimating resolution as 304
Segmentation fault (core dumped)

I search on internet and I try change my TESSDATA_PREFIX to export TESSDATA_PREFIX=/usr/local/share/tessdata or ...share/tessract-ocr/4.00 or 5/tessdata and tesseract/tessdata** this paths is not working for me. I have eng.traineddata file on all this locations. But I'm still getting this error and I try change traineddata file from github. But I'm still getting this error.

Here is my code

#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(){
cv::Mat image;
string outText;
image = cv::imread("text.png",cv::IMREAD_COLOR);

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng", tesseract::OEM_LSTM_ONLY);
api->SetPageSegMode(tesseract::PSM_AUTO);
api->SetImage(image.data, image.cols, image.rows, 3, image.step);
outText = string(api->GetUTF8Text());
cout << outText;
api->End();
    
}

My Makefile

CC = g++
PROJECT = main
SRC = main.cpp
LIBS = `pkg-config --cflags --libs opencv4 tesseract`
$(PROJECT) : $(SRC)
    $(CC) $(SRC) $(LIBS) -o $(PROJECT) 

Here is the error message

Error opening data file /usr/local/share/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
Estimating resolution as 304
Segmentation fault (core dumped)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城月光淡如水﹏ 2025-02-17 00:50:04

init()方法中设置第一个参数,以指定“ Eng.trainedData”的文件路径
并将第三参数设置为oem_default
在以下之前:

api->Init(NULL, "eng", tesseract::OEM_LSTM_ONLY);

至:
ex)

api->Init(C:\tesseract\tessdata, "eng", tesseract::OEM_DEFAULT);

set the first parameter in Init() method to specify the file path that "eng.traineddata" located
and set the 3rd parameter to OEM_DEFAULT
before :

api->Init(NULL, "eng", tesseract::OEM_LSTM_ONLY);

as to :
ex)

api->Init(C:\tesseract\tessdata, "eng", tesseract::OEM_DEFAULT);

tessdata folder path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文