2014-11-22 108 views
1

大家好我在计算机科学(bd),为我的考试项目我想使ac crr程序(无gui),我在因特网上搜索tesseract,但我不找到c的任何API,但只为c + +,任何人都知道c语言的ocr api?在C项目中包含OCR Api

在此先感谢

回答

2

这是使用的Tesseract C API的例子,从official documentation采取:

#include <stdio.h> 
#include <allheaders.h> 
#include <capi.h> 

void die(const char *errstr) { 
     fputs(errstr, stderr); 
     exit(1); 
} 

int main(int argc, char *argv[]) { 
     TessBaseAPI *handle; 
     PIX *img; 
     char *text; 

     if((img = pixRead("img.png")) == NULL) 
       die("Error reading image\n"); 

     handle = TessBaseAPICreate(); 
     if(TessBaseAPIInit3(handle, NULL, "eng") != 0) 
       die("Error initialising tesseract\n"); 

     TessBaseAPISetImage2(handle, img); 
     if(TessBaseAPIRecognize(handle, NULL) != 0) 
       die("Error in Tesseract recognition\n"); 

     if((text = TessBaseAPIGetUTF8Text(handle)) == NULL) 
       die("Error getting text\n"); 

     fputs(text, stdout); 

     TessDeleteText(text); 
     TessBaseAPIEnd(handle); 
     TessBaseAPIDelete(handle); 
     pixDestroy(&img); 

     return 0; 
} 

如果你使用Linux,你可以compile it as you would compile a program using C++ API