Tesseract无法加载任何语言问题
我在互联网上搜索,然后尝试将我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
init()
方法中设置第一个参数,以指定“ Eng.trainedData”的文件路径并将第三参数设置为
oem_default
在以下之前:
至:
ex)
set the first parameter in
Init()
method to specify the file path that "eng.traineddata" locatedand set the 3rd parameter to
OEM_DEFAULT
before :
as to :
ex)