声明Tesseract OCR TessBaseAPI的问题

时间:2014-12-21 14:35:02

标签: visual-studio-2013 tesseract

我是Tesseract API的新手。目前我在Visual Studio 2013上运行Wiki中的示例程序,程序如下。

#include "leptonica\allheaders.h"
#include "iostream"
#include "api\baseapi.h"
#include "stdio.h"

using namespace std;
using namespace tesseract;

int main(int argc, char** argv)
{
char* outText;

TessBaseAPI *api = new TessBaseAPI();

// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng")) 
{
    fprintf(stderr, "Could not initialize tesseract.\n");
    exit(1);
}

// Open input image with leptonica library
Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif");
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);

// Destroy used object and release memory
api->End();
delete[] outText;
pixDestroy(&image);

return 0;
}

当我使用VS2013编译它时,我收到以下错误。

1>------ Build started: Project: OCRTest, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\tesseract-build\include\leptonica\pix.h(209): warning C4305: 'initializing' : truncation        from 'double' to 'const l_float32'
1>c:\tesseract-build\include\leptonica\pix.h(211): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\tesseract-ocr\api\baseapi.h(32): fatal error C1083: Cannot open include file: 'platform.h': No such file or directory
 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我相信我没有正确构建tesseract源,但我不能确定。另外,声明

TessBaseAPI * api = new TessBaseAPI() 
当光标移过TessBaseAPI()时,

会抛出诸如'type specifier expected'之类的错误。非常感谢帮助,并提前感谢您!

1 个答案:

答案 0 :(得分:1)

假设您使用的是Tesseract 3.02.02& leptonica 1.68图书馆。

请按照以下步骤操作。

  1. 请务必在安装Tesseract时检查Tesseract Development files选项

  2. Project solutions -> VC++ Directories

    中添加以下文件夹
    C:\Program Files\Tesseract-OCR\include
    C:\Program Files\Tesseract-OCR\include\tesseract
    C:\Program Files\Tesseract-OCR\include\leptonica
    
  3. Project solutions -> VC++ Directories

    中添加以下lib文件夹
      

    C:\ Program Files \ Tesseract-OCR \ lib

  4. Configuration Properties -> Linker->Input ->Additional Dependencies

    中添加其他依赖项
    libtesseract302.lib
    libtesseract302d.lib
    liblept168.lib
    liblept168d.lib
    
  5. 一般计划结构

  6.   

    
    
    > 
    >     #include <baseapi.h>
    >     #include <allheaders.h>
    >     #include <iostream>
    > 
    >     using namespace std;
    > 
    >     int main(void)
    >     {
    >      tesseract::TessBaseAPI api;
    >      //...
    >     }
    > 
    > 
    &#13;
    &#13;
    &#13;