将ctypes与tesserac-ocr TessPageIteratorBoundingBox一起使用时异常

问题描述 投票:0回答:1
import ctypes
import os
os.putenv("PATH", r'C:\Program Files\Tesseract-OCR')
os.environ["TESSDATA_PREFIX"] = r'C:\Program Files\Tesseract-OCR\tessdata'

liblept = ctypes.cdll.LoadLibrary('liblept-5.dll')
pix = liblept.pixRead('test.png'.encode())
print(pix)

tesseractLib = ctypes.cdll.LoadLibrary('libtesseract-5.dll')

tesseractHandle = tesseractLib.TessBaseAPICreate()

tesseractLib.TessBaseAPIInit3(tesseractHandle, '.', 'eng')

tesseractLib.TessBaseAPISetImage2(tesseractHandle, pix)

# text_out = tesseractLib.TessBaseAPIGetUTF8Text(tesseractHandle)
# print(ctypes.string_at(text_out))

tessPageIterator = tesseractLib.TessResultIteratorGetPageIterator(tesseractHandle)
iteratorLevel = 3  # RIL_BLOCK,  RIL_PARA,  RIL_TEXTLINE,  RIL_WORD,  RIL_SYMBOL
tesseractLib.TessPageIteratorBoundingBox(tessPageIterator, iteratorLevel, ctypes.c_int(0), ctypes.c_int(0), ctypes.c_int(0), ctypes.c_int(0))


我有例外:

Traceback (most recent call last):
  File "D:\BaiduYunDownload\programming\Python\CtypesOCR.py", line 25, in <module>
    tesseractLib.TessPageIteratorBoundingBox(tessPageIterator, iteratorLevel, ctypes.c_int(0), ctypes.c_int(0), ctypes.c_int(0), ctypes.c_int(0))
OSError: exception: access violation reading 0x00000018

那么怎么了?该程序的目的是获得每个单词的边界矩形。我知道像tesserocrPyOCR]这样的项目

P.S。在这里指定DLL函数所需的参数类型(函数原型)并不重要。可以不加注释的行,而注释最后三行以对其进行测试。我之前发布了question,并且由于这个原因它已关闭

导入ctypes导入os os.putenv(“ PATH”,r'C:\ Program Files \ Tesseract-OCR')os.environ [“ TESSDATA_PREFIX”] = r'C:\ Program Files \ Tesseract-OCR \ tessdata' liblept = ctypes.cdll.LoadLibrary('liblept-5 ....

python c++ c tesseract ctypes
1个回答
0
投票

我自己解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.