sirfz / tesserocr

A Python wrapper for the tesseract-ocr API
MIT License
2.02k stars 255 forks source link

in loop `GetChoiceIterator` crashs python if result is empty #325

Open NewUserHa opened 1 year ago

NewUserHa commented 1 year ago
api = tesserocr.PyTessBaseAPI()

api.SetImage(image)
api.Recognize()

ri = api.GetIterator()
level = tesserocr.RIL.SYMBOL
for r in tesserocr.iterate_level(ri, level):
    ci = r.GetChoiceIterator()
    for _ in ci:
        print(123) # crash before this print

api.End()

error result_it.it_->word() != nullptr:Error:Assert failed:in file C:\projects\tesserocr-windows-build\tesseract\src\ccmain\ltrresultiterator.cpp, line 383 when encountering an empty api.GetUTF8Text().

I guess the issue is probably around https://github.com/sirfz/tesserocr/blob/2fd8eb53f337a289ce557132cd0ac7e0048a2fcc/tesserocr.pyx#L1112