Ошибка с Tesseract-OCR, связанная с tesseract :: TessBaseApi () (ожидаемый спецификатор типа) - PullRequest
0 голосов
/ 20 октября 2018

Я создал программу с использованием openCV 2.4.9 и tesseract 3.04, оба с использованием API C.

Поскольку C API openCV устарел, я решил изменить его, чтобы использовать API C ++ обеих библиотек..

Эта часть кода в C (работает):

    #include <cv.h>
    #include <tesseract/capi.h>

void    foo (struct _IplImage  *imgptr)
{
    struct TessBaseAPI  *handle_ocr;
    handle_ocr  = TessBaseAPICreate();
    // Do something
}

должна быть эквивалентна этому коду в C ++ (не компилируется):

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

void    foo (class cv::Mat  *imgptr)
{
    class tesseract::TessBaseAPI    *handle_ocr;
    handle_ocr  = new tesseract::TessBaseApi();
    // Do something
}

g ++ 6 (в Debian Stretch) выдает следующую ошибку:

error: expected type-specifier
  handle_ocr = new tesseract::TessBaseApi();
                   ^~~~~~~~~

Что это значит?И каково решение?

РЕДАКТИРОВАТЬ: Весь исходный файл:

/******************************************************************************
 ******* headers **************************************************************
 ******************************************************************************/
 /* Standard C ----------------------------------------------------------------*/
        /* snprintf() */
    #include <cstdio>

/* Packages ------------------------------------------------------------------*/
        /* opencv */
    #include <opencv2/opencv.hpp>
        /* OCR Tesseract */
    #include <tesseract/baseapi.h>
    #include <leptonica/allheaders.h>

/* Module --------------------------------------------------------------------*/
        /* img_ocr_text & OCR_TEXT_MAX */
    #include "some_other_file.hpp"

    #include "this_file.hpp"


/******************************************************************************
 ******* func *****************************************************************
 ******************************************************************************/
void    foo (class cv::Mat  *imgptr)
{
    class tesseract::TessBaseAPI    *handle_ocr;

    /* Language */
    char    *lang_str   = "eng";

    /* Config file */
    char    *conf_str   = "/home/user/ocr/price";

    /* init OCR */
    handle_ocr  = new tesseract::TessBaseApi();
    handle_ocr->Init(NULL, lang_str, tesseract::OEM_TESSERACT_CUBE_COMBINED);
    if (conf) {
        /* Configure OCR (whitelist chars) */
        handle_ocr->ReadConfigFile(conf_str);
    }

    /* scan image for text */
    handle_ocr->SetImage(imgptr->data,
                imgptr->size().width, imgptr->size().height,
                imgptr->channels(), imgptr->step1());
    char    *txt;
    txt = handle_ocr->GetUTF8Text();

    /* Copy text to global variable */
    snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt);

    /* cleanup */
    delete []   txt;
    handle_ocr->Clear();
    handle_ocr->End();
}


/******************************************************************************
 ******* end of file **********************************************************
 ******************************************************************************/

1 Ответ

0 голосов
/ 20 октября 2018

Замените это:

handle_ocr  = new tesseract::TessBaseApi();

на это:

handle_ocr  = new tesseract::TessBaseAPI();

Ошибка была в верхнем / нижнем регистре.

...