In tesserocr, When I initailize api with oem and psm options to run DetectOS, it raises error(Fatal Python error: Aborted). Why?

Issue:

In tesserocr, When I initialize api with oem and psm options to run DetectOS or DetectOrientationScript, it raises error(Fatal Python error: Aborted). Why this happened? codes:

from tesserocr import PyTessBaseAPI, PSM, OEM

img_path = r'C:UserszlDesktopasd.png'
tessdata = r'E:WorkspacePycharmocr-testdatatessdatatessdata-4.1.0\'
def test3_4():
    with PyTessBaseAPI(path=tessdata, lang='chi_sim+eng', psm=PSM.OSD_ONLY, oem=OEM.LSTM_ONLY) as api:
        api.SetImageFile(img_path)
        os = api.DetectOrientationScript()
        print("Orientation: {orient_deg}nOrientation confidence: {orient_conf}n"
              "Script: {script_name}nScript confidence: {script_conf}".format(**os))

output:

D:Anaconda3envsdev-ocr-testpython.exe "D:/JetBrains/PyCharm 2023.3.2/plugins/python/helpers/pycharm/_jb_pytest_runner.py" --target test_g_lts/test_ocr_algorithm/test_ocr_engine/test_tesseract_ocr_engine/test_tesseract_ocr_api.py::test3_4 
Testing started at 23:16 ...
Launching pytest with arguments test_g_lts/test_ocr_algorithm/test_ocr_engine/test_tesseract_ocr_engine/test_tesseract_ocr_api.py::test3_4 --no-header --no-summary -q in E:WorkspacePycharmocr-testtest

============================= test session starts =============================
collecting ... collected 1 item

test_g_lts/test_ocr_algorithm/test_ocr_engine/test_tesseract_ocr_engine/test_tesseract_ocr_api.py::test3_4 Fatal Python error: Aborted

Current thread 0x000009fc (most recent call first):
  File "E:WorkspacePycharmocr-testtesttest_g_ltstest_ocr_algorithmtest_ocr_enginetest_tesseract_ocr_enginetest_tesseract_ocr_api.py", line 241 in test3_4
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestpython.py", line 159 in pytest_pyfunc_call
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_callers.py", line 103 in _multicall
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_manager.py", line 120 in _hookexec
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_hooks.py", line 513 in __call__
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestpython.py", line 1627 in runtest
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestrunner.py", line 174 in pytest_runtest_call
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_callers.py", line 103 in _multicall
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_manager.py", line 120 in _hookexec
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_hooks.py", line 513 in __call__
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestrunner.py", line 242 in <lambda>
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestrunner.py", line 341 in from_call
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestrunner.py", line 241 in call_and_report
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestrunner.py", line 132 in runtestprotocol
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestrunner.py", line 113 in pytest_runtest_protocol
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_callers.py", line 103 in _multicall
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_manager.py", line 120 in _hookexec
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_hooks.py", line 513 in __call__
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestmain.py", line 362 in pytest_runtestloop
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_callers.py", line 103 in _multicall
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_manager.py", line 120 in _hookexec
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_hooks.py", line 513 in __call__
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestmain.py", line 337 in _main
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestmain.py", line 283 in wrap_session
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestmain.py", line 330 in pytest_cmdline_main
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_callers.py", line 103 in _multicall
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_manager.py", line 120 in _hookexec
  File "D:Anaconda3envsdev-ocr-testlibsite-packagespluggy_hooks.py", line 513 in __call__
  File "D:Anaconda3envsdev-ocr-testlibsite-packages_pytestconfig__init__.py", line 175 in main
  File "D:JetBrainsPyCharm 2023.3.2pluginspythonhelperspycharm_jb_pytest_runner.py", line 60 in <module>

Process finished with exit code 3

Even though I actually ran it in the Main method, the program exited when I called DetectOrientationScript. Code:

from tesserocr import PyTessBaseAPI, PSM, OEM

img_path = r'C:UserszlDesktopasd.png'
tessdata = r'E:WorkspacePycharmocr-testdatatessdatatessdata-4.1.0\'


def main():
    with PyTessBaseAPI(path=tessdata, lang='chi_sim+eng', psm=PSM.OSD_ONLY, oem=OEM.LSTM_ONLY) as api:
        api.SetImageFile(img_path)
        print('asdasdasdasdasdasdasd')
        os = api.DetectOrientationScript()
        print('asdasdasdasdasdasdasd')
        print("Orientation: {orient_deg}nOrientation confidence: {orient_conf}n"
              "Script: {script_name}nScript confidence: {script_conf}".format(**os))
        print('asdasdasdasdasdasdasd')


if __name__ == "__main__":
    main()

output:

D:Anaconda3envsdev-ocr-testpython.exe E:WorkspacePycharmocr-testtesttest_g_ltstest_ocr_algorithmtest_ocr_enginetest_tesseract_ocr_enginett.py 
asdasdasdasdasdasdasd

Process finished with exit code -1073740791 (0xC0000409)

exit code -1073740791 (0xC0000409): STATUS_STACK_BUFFER_OVERRUN.

Background:

  • tesseract version:

    tesseract 5.3.4

    leptonica-1.84.1 (May 1 2024, 20:55:26) [MSC v.1939 LIB Release x64]

    libgif 5.2.1 : libjpeg 9f : libpng 1.6.43 : libtiff 4.6.0 : zlib 1.3.1 : libwebp 1.4.0 : libopenjp2 2.5.2

  • tessdata: 4.1.0

  • Python 3.9.19

  • install tesserocr from tesserocr-windows-build, tessdata from tessdata.

Trying:

  1. trying 1:

    with PyTessBaseAPI(path=tessdata, lang='chi_sim+eng', oem=OEM.LSTM_ONLY) as api:
     api.SetImageFile(img_path)
     print(api.GetUTF8Text())
    

    case pass, which means:

    • the path of tessdata is right and language data are loaded successfully.
    • the language data is compatible with the LSTM mode.
  2. trying 2:

    with PyTessBaseAPI(path=tessdata, lang='chi_sim+eng', psm=PSM.OSD_ONLY, oem=OEM.TESSERACT_LSTM_COMBINED) as api:
     api.SetImageFile(img_path)
     os = api.DetectOS()
     print(
         "Orientation: {orientation}nOrientation confidence: {oconfidence}nScript: {script}nScript confidence: {sconfidence}".format(
             **os))
    

    case pass, means:

    OSD is compatible with the LSTM mode.

    maybe? the doc says “Run the LSTM recognizer, but allow fallback to Tesseract when things get difficult.”, maybe is Tesseract do the all of the work, while the LSTM is shutdown.

    And I asked GPT too, “The LSTM mode is incompatible with the OSD mode” is one of the answers. So the incompatibility between LSTM and OSD leads to STATUS_STACK_BUFFER_OVERRUN?

Expecting:

  • The reason that caused this error. Is it like GPT says “The LSTM mode is incompatible with the OSD mode”, or other reasons.

PS:
the hover hints of PyTessBaseAPI is really different from the real code doc comment. The __init__ method only have two args, but the doc says there are more args. The hover hints really mislead me.
hover hints image, doc comment image

7

This problem is indeed caused by the incompatibility between LSTM_ONLY and OSD_ONLY. If you do need to use OSD and LSTM, you need to use OEM.DEFAULT. And the another solution what sets the LSTM_ONLY through SetVariable method will change OEM to DEFAULT internally to ensure compatibility, rather than sets OEM as LSTM_ONLY.

with PyTessBaseAPI(path=TESSDATA_DIRECTORY, lang='chi_sim+eng') as api:
    api.SetVariable('tessedit_ocr_engine_mode', str(OEM.LSTM_ONLY))
    api.SetPageSegMode(psm=PSM.OSD_ONLY)
    api.SetImageFile(TEST_IMAGE_ABSOLUTE_PATH[0])
    os = api.DetectOrientationScript()
    print(
        "Orientation: {orient_deg}nOrientation confidence: {orient_conf}nScript: {script_name}nScript confidence: {script_conf}".format(
            **os))
    print(api.oem())  # 3 => OEM.DEFAULT

@user898678 Thanks for your comments.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật