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)
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);