python2使用tesseract C-API崩溃

时间:2018-01-16 08:43:03

标签: python tesseract

我已经安装了tesseract4.0,并且可以通过命令行使用tesseract来识别图片。但是当我尝试根据official wiki使用C-API时,python程序与Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)崩溃,并且没有其他错误信息。它在第rc = tesseract.TessBaseAPIInit3(api, TESSDATA_PREFIX, lang)行坠毁。这是我的代码:

# -*- coding: utf-8 -*-

import os
import ctypes

lang = "chi_sim"
filename = "/Users/pzx/Desktop/test.png"
libname = "/usr/local/lib/libtesseract.4.dylib"
TESSDATA_PREFIX = os.environ.get('TESSDATA_PREFIX')
if not TESSDATA_PREFIX:
    TESSDATA_PREFIX = "/usr/local/share"

tesseract = ctypes.cdll.LoadLibrary(libname)
tesseract.TessVersion.restype = ctypes.c_char_p
tesseract_version = tesseract.TessVersion()
api = tesseract.TessBaseAPICreate()
rc = tesseract.TessBaseAPIInit3(api, TESSDATA_PREFIX, lang)
if (rc):
    tesseract.TessBaseAPIDelete(api)
    print("Could not initialize tesseract.\n")
    exit(3)

text_out = tesseract.TessBaseAPIProcessPages(api, filename, None, 0)
result_text = ctypes.string_at(text_out)

print 'Tesseract-ocr version', tesseract_version
print result_text

这是我的tesseract版本信息:

tesseract 4.00.00alpha
 leptonica-1.74.4
  libjpeg 9b : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11

 Found AVX2
 Found AVX
 Found SSE

python版本信息:

Python 2.7.14 (default, Sep 25 2017, 09:53:22)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

我该如何解决,每个答案都会受到赞赏。

0 个答案:

没有答案