我是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'之类的错误。非常感谢帮助,并提前感谢您!
答案 0 :(得分:1)
假设您使用的是Tesseract 3.02.02& leptonica 1.68图书馆。
请按照以下步骤操作。
请务必在安装Tesseract时检查Tesseract Development files
选项
在Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\include C:\Program Files\Tesseract-OCR\include\tesseract C:\Program Files\Tesseract-OCR\include\leptonica
在Project solutions -> VC++ Directories
C:\ Program Files \ Tesseract-OCR \ lib
在Configuration Properties -> Linker->Input ->Additional Dependencies
libtesseract302.lib libtesseract302d.lib liblept168.lib liblept168d.lib
一般计划结构
&#13;&#13;&#13;&#13;&#13;> > #include <baseapi.h> > #include <allheaders.h> > #include <iostream> > > using namespace std; > > int main(void) > { > tesseract::TessBaseAPI api; > //... > } > >