Recognizing and reading text from an image using tesseract and opencv in c++? [closed]

asked 2018-09-02 11:53:36 -0600

mayra gravatar image

updated 2018-09-02 13:26:15 -0600

I am trying to recognize text from an image and I am using Tesseract and opencv for this. The code I have used for this is below.

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

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
    string outText;
    string imPath = "Images/newspaper2.jpeg";

    // Create Tesseract object
    tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();

    // Initialize tesseract to use English (eng) and the LSTM OCR engine. 
    ocr->Init("tessdata", "eng", tesseract::OEM_LSTM_ONLY);

    // Set Page segmentation mode to PSM_AUTO (3)

    // Open input image using OpenCV
    Mat im = cv::imread(imPath, IMREAD_COLOR);

    // Set image data
    ocr->SetImage(, im.cols, im.rows, 3, im.step);

    // Run Tesseract OCR on image
    outText = string(ocr->GetUTF8Text());

    // print recognized text
    cout << outText << endl; // Destroy used object and release memory ocr->End();

    return EXIT_SUCCESS;

But I am facing an error while I am executing this. Error is namespace "tesseract" has no member "oem_lstm_only". It is having problems in initializing tesseract to use English (eng) and the LSTM OCR engine. But I am using tesseract version 3.2 only so LSTM OCR engine should work fine. Can anyone please tell me why I am getting this error and how can I solve this.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by LBerger
close date 2018-09-02 13:08:56.810430



Your question is about tesseract( tesseract::TessBaseAPI is not an opencv class) and not opencv

I think proper fora is!for...

LBerger gravatar imageLBerger ( 2018-09-02 13:08:40 -0600 )edit