Reputation: 567
I downloaded tesseract, and I want to use it in c++ code. but I get these error:
TessOp.cpp:6:39: fatal error: tesseract-ocr/api/baseapi.h: No such file or directory
In my code I also use OpenCV, this is my code:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <tesseract-ocr/api/baseapi.h>
#include <iostream>
int main(int argc, char** argv)
{
// Load image
cv::Mat im = cv::imread("1.png");
if (im.empty())
{
std::cout << "Cannot open source image!" << std::endl;
return -1;
}
cv::Mat gray;
cv::cvtColor(im, gray, CV_BGR2GRAY);
// ...other image pre-processing here...
//Mat binary_image;
//threshold(gray,binary_image, 25, 255, CV_THRESH_BINARY);
//imshow("binary_image",binary_image);
// Pass it to Tesseract API
tesseract::TessBaseAPI tess;
//tess.Init("C:/Tesseract-OCR/tessdata/", "eng");
tess.Init(NULL, "eng", tesseract::OEM_DEFAULT);
tess.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
tess.SetImage((uchar*)gray.data, gray.cols, gray.rows, 1, gray.cols);
// Get the text
char* out = tess.GetUTF8Text();
std::cout << out << std::endl;
return 0;
}
I put the file in samples folders in OpenCV directory,since I use OpenCV in the code; I run the file using this command :
g++ `pkg-config opencv --cflags` my_code.cpp -o my_code `pkg-config opencv --libs`
Upvotes: 1
Views: 1421
Reputation: 1043
You are not adding the include directory of tesseract nor are you linking it. Add the following to command line
-I/usr/local/include/tesseract -ltesseract
Upvotes: 1