I want to convert the C++ version Result iterator example in tesseract-ocr doc to Python.
Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif");
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng");
api->SetImage(image);
api->Recognize(0);
tesseract::ResultIterator* ri = api->GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_WORD;
if (ri != 0) {
do {
const char* word = ri->GetUTF8Text(level);
float conf = ri->Confidence(level);
int x1, y1, x2, y2;
ri->BoundingBox(level, &x1, &y1, &x2, &y2);
printf("word: '%s'; \tconf: %.2f; BoundingBox: %d,%d,%d,%d;\n",
word, conf, x1, y1, x2, y2);
delete[] word;
} while (ri->Next(level));
}
What I could do till right now is the following :
import ctypes
liblept = ctypes.cdll.LoadLibrary('liblept-5.dll')
pix = liblept.pixRead('11.png'.encode())
print(pix)
tesseractLib = ctypes.cdll.LoadLibrary(r'C:\Program Files\tesseract-OCR\libtesseract-4.dll')
tesseractHandle = tesseractLib.TessBaseAPICreate()
tesseractLib.TessBaseAPIInit3(tesseractHandle, '.', 'eng')
tesseractLib.TessBaseAPISetImage2(tesseractHandle, pix)
#tesseractLib.TessBaseAPIRecognize(tesseractHandle, tesseractLib.TessMonitorCreate())
I cannot convert the C++ api->Recognize(0)
to Python(what I have tried is in the last line(commented) of the code, but it is wrong), I am not experienced with C++, so I cannot go on anymore, anyone can help with the conversion ? The APIs:
From the source code: https://github.com/tesseract-ocr/tesseract/blob/420cbac876b06beeee271d9f44ba800d943a8a83/include/tesseract/capi.h
I guess I also have some difficulty on the subsequent conversion , for example , I don't know how to denote tesseract::RIL_WORD
in Python, so it would be kind to provide me a full version of the conversion , thanks !
I know there is a project named tesserocr can save me from the conversion , but the problem with the project is they don't provide an uptodate windows Python wheels, which is the main reason for me to do the conversion .