1

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`
1
  • I am facing same problem . let me know how to solve this problem ? Commented May 14, 2014 at 10:54

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.