problem on using ctypes with tesserac-ocr TessPageIteratorBoundingBox

0
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-4.dll')
pix = liblept.pixRead('test.png'.encode()) 
print(pix)

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

tesseractHandle = tesseractLib.TessBaseAPICreate()

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

tesseractLib.TessBaseAPISetImage2(tesseractHandle, pix)

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))

I got exceptions :

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

So what's wrong ? The aim of this program is to get bounding rectangle of each word. I know projects like tesserocr and PyOCR

P.S. Specifying the required argument types (function prototypes) for the DLL functions doesn't matter here.

python
c++
c
tesseract
ctypes
asked on Stack Overflow Feb 12, 2020 by iMath • edited Feb 12, 2020 by iMath

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0