ctypes
我使用并tesseract 3.0.2
参考示例编写了一个片段:
import ctypes
from PIL import Image
libname = '/opt/tesseract/lib/libtesseract.so.3.0.2'
tesseract = ctypes.cdll.LoadLibrary(libname)
api = tesseract.TessBaseAPICreate()
rc = tesseract.TessBaseAPIInit3(api, "", 'eng')
filename = '/opt/ddl.ddl.exp654.png'
text_out = tesseract.TessBaseAPIProcessPages(api, filename, None, 0)
result_text = ctypes.string_at(text_out)
print result_text
它将文件名作为参数传递,我不知道调用API中的哪个方法来传递原始数据,例如:
tesseract.TessBaseAPIWhichMethod(api, open(filename).read())