【问题标题】:Build error with C API of Tesseract OCR使用 Tesseract OCR 的 C API 构建错误
【发布时间】:2011-10-11 12:20:26
【问题描述】:

使用using the API 和另一个how to get the image data into a format recognizable by Tesseract 上的链接,我编写了以下代码,并将...tesseract/ccmain/ 目录添加到我的Visual C++ 项目(已用于OpenCV)的Include Directories 中。

#include "baseapi.h"

..... [OpenCV 代码等]....

//********************* Tesseract OCR function calls *********************************************

 // create a temp buffer 
    unsigned char *buffer,*temp2; 
    buffer = new unsigned char[plate->width*plate->height*plate->nChannels]; 
    //'plate' is an IplImage*
    temp2 = buffer; 
    // pointer to imageData 
    unsigned char *temp1 = (unsigned char*) plate->imageData; 
    // copy imagedata to buffer row by row 
    for(i=0;i<plate->height;i++) 
    { 
            memcpy(temp2, temp1, plate->width*plate->nChannels); 
            // imageData jump to next line 
            temp1 = temp1 + plate->widthStep; 
            // buffer jump to next line 
            temp2 = temp2+ plate->width*plate->nChannels; 
    } 

     TessBaseAPI::InitWithLanguage(NULL, NULL, "eng", NULL, false, 0, NULL);
  char* Text = TessBaseAPI::TesseractRect( buffer, 8, 8,
                               0, 0, plate->width,plate->height);
  TessBaseAPI::End();

  printf("\n%s", Text );

它编译时没有任何错误,但是当我尝试构建它时,每个与 Tesseract 相关的函数调用都会出现此错误:“未解析的外部符号 XXXXX。” 我在链接和包含 Tesseract 时是否犯了任何错误,它没有出现在编译时,而只出现在构建时?

任何帮助都会很棒。

编辑:这些是错误消息:

Linking...
image.obj : error LNK2001: unresolved external symbol "public: static void __cdecl TessBaseAPI::End(void)" (?End@TessBaseAPI@@SAXXZ)
image.obj : error LNK2001: unresolved external symbol "public: static char * __cdecl TessBaseAPI::TesseractRect(unsigned char const *,int,int,int,int,int,int)" (?TesseractRect@TessBaseAPI@@SAPADPBEHHHHHH@Z)
image.obj : error LNK2001: unresolved external symbol "public: static int __cdecl TessBaseAPI::InitWithLanguage(char const *,char const *,char const *,char const *,bool,int,char * * const)" (?InitWithLanguage@TessBaseAPI@@SAHPBD000_NHQAPAD@Z)
Debug/proj.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
Creating browse info file...

proj.exe - 4 error(s), 0 warning(s)

【问题讨论】:

  • 好的,我正在运行 Tesseract 的命令行,方法是使用 stdlib.h 中的 system() 函数将“tesseract image.tif text -l eng”传递给 shell。这是一件非常艰难的事情,但是 API 确实比它的价值更麻烦!

标签: visual-studio visual-c++ image-processing opencv tesseract


【解决方案1】:

您需要找到相关的 .LIB 文件并将它们链接到您的项目。

【讨论】:

  • 仅找到 tessdll.lib 并将其包含在内。仍然存在相同的构建错误。有什么想法吗?
【解决方案2】:

您好,请您尝试以下代码...

#define TESSDLL_IMPORTS
#include "stdafx.h"
#include "baseapi.h"
#include <string>

using namespace std;

int main(int argc, char **argv)
{
    string outfile;
    tesseract::TessBaseAPI api;

    return 0;
}

【讨论】:

  • 仍然存在构建错误,我一定是在包含库时犯了一些错误。无论如何,谢谢,尽管我在程序中使用了 Tesseract 的命令行参数。那样工作得很好。 API 似乎比它的价值更麻烦!
猜你喜欢
  • 2017-09-29
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-21
  • 1970-01-01
  • 2019-07-15
相关资源
最近更新 更多