繁体   English   中英

与tesseract :: TessBaseApi()有关的Tesseract-OCR错误(预期的类型说明符)

[英]Error with Tesseract-OCR relating tesseract::TessBaseApi() (expected type-specifier)

我使用C API编写了使用openCV 2.4.9和tesseract 3.04的程序。

由于不赞成使用openCV的C API,因此我决定对其进行修改,以使用两个库的C ++ API。

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上)给出以下错误:

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 **********************************************************
 ******************************************************************************/

替换为:

handle_ocr  = new tesseract::TessBaseApi();

有了这个:

handle_ocr  = new tesseract::TessBaseAPI();

大写/小写错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM