有没有一种方法可以构建和使用Tesseract库以及相应的Leptonica库(因为Tesseract依赖于Leptonica),就像在Windows中那样?
我按照它们的说明编译了这些库,但似乎 libtesseract.so.3.0.2
包含了一个固定路径到Leptonica共享库:
$ ldd libtesseract.so.3.0.2
linux-vdso.so.1 => (0x00007fffbc5ff000)
**liblept.so.4 => /usr/local/lib/liblept.so.4 (0x00007fa8400fd000)**
libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x00007fa83fcae000)
libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x00007fa83fa5e000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa83f5e4000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa83f2de000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa83f059000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa83ecc5000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa83eaaf000)
/lib64/ld-linux-x86-64.so.2 (0x0000003080200000)
在没有安装Leptonica的工作站上运行应用程序时,会导致OSError错误:
OSError: liblept.so.4: cannot open shared object file: No such file or directory
典型的使用情况如下(tesseract和leptonica库位于同一文件夹中):
import ctypes
import os
import sys
lang = 'eng'
os.putenv('TESSDATA_PREFIX', ".")
tessdata = os.environ.get('TESSDATA_PREFIX')
tess_libpath = "."
tess_libname = "libtesseract.so.3.0.2"
# tess_libname = "libtesseract302.dll" works in Windows, no need to add a leponica library file
os.environ["PATH"] += os.pathsep + tess_libpath
tesseract = None
try:
tesseract = ctypes.cdll.LoadLibrary(os.path.join(tess_libpath, tess_libname))
except OSError, err:
raise
class _TessBaseAPI(ctypes.Structure): pass
TessBaseAPI = ctypes.POINTER(_TessBaseAPI)
tesseract.TessBaseAPICreate.restype = TessBaseAPI
tesseract.TessBaseAPIDelete.restype = None
tesseract.TessBaseAPIDelete.argtypes = [TessBaseAPI]
tesseract.TessBaseAPIInit3.argtypes = [TessBaseAPI,
ctypes.c_char_p,
ctypes.c_char_p]
tesseract.TessBaseAPISetImage.restype = None
tesseract.TessBaseAPISetImage.argtypes = [TessBaseAPI,
ctypes.c_void_p,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int]
tesseract.TessBaseAPIGetUTF8Text.restype = ctypes.c_char_p
tesseract.TessBaseAPIGetUTF8Text.argtypes = [TessBaseAPI]
我尝试在配置Tesseract时添加选项
--disable-shared --enable-static
,但是没有成功。在我的情况下目标操作系统是CentOS 6.5,但我也会欣赏任何一般的答案。