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

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

本文关键字:说明符 类型 出错 tesseract TessBaseApi Tesseract-OCR      更新时间:2023-10-16

我用 openCV 2.4.9 和 tesseract 3.04 做了一个程序,两者都使用 C API。

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

替换这个:

handle_ocr  = new tesseract::TessBaseApi();

有了这个:

handle_ocr  = new tesseract::TessBaseAPI();

这是大写/小写的错误。