naptha / tesseract.js

Pure Javascript OCR for more than 100 Languages 📖🎉🖥
http://tesseract.projectnaptha.com/
Apache License 2.0
35.31k stars 2.23k forks source link

Error on iOS 17 for Legacy Model (OEM 0) #867

Closed rin-st closed 10 months ago

rin-st commented 10 months ago

Issue is mostly copypaste of https://github.com/naptha/tesseract.js/issues/804 but with newer versions and slightly different error message

Tesseract.js version (version number for npm/GitHub release, or specific commit for repo) 5.0.4

Describe the bug On iOS 17's Safari/WebKit, when

const worker = await createWorker('eng', 0);
await worker.recognize(imageData);

is called, the following runtime error will occur:

Error: RuntimeError: call_indirect to a null table entry (evaluating '(Tf=b._emscripten_bind_TessBaseAPI_Recognize_1= b.asm.Dd).apply(null,arguments)')

No errors on MacOS, Android and iOS 16

To Reproduce Steps to reproduce the behavior:

Set up Tesseract on a Nextjs project Visit Next website on an iOS device running iOS 17.2.1 Upload image See error

Input image: My passport photo (Iphone 14 pro) with Machine readable zone (MRZ). Tried ~10+ different photos. Interested in recognizing MRZ.

Expected behavior Tesseract will recognize the text in the image and output successfully.

Device Version:


Other OEM versions doesn't cause an error, but recognizing doesn't work as expected

Balearica commented 10 months ago

It looks like the core issue is essentially where we left off the discussion for #804. The LSTM model (oem value 1), which is the default model, runs on iOS 17 while the Legacy model (oem value 0) does not.

While I sympathize with the fact that this is annoying, unfortunately there is not much I can personally do. There does not appear to be anything objectively wrong with the Tesseract.js code, seeing as it runs on every platform including iOS prior to iOS v17. Apple requires you to own a new(ish) iPhone and Mac to debug iOS browsers, and I own neither, so I cannot investigate iOS 17-specific behaviors. Somebody else would have to investigate this.

Balearica commented 10 months ago

@rin-st Using various devices from Browserstack, I attempted to replicate this error using the Legacy demo site from #804 (seen here) and while I was able to do so for 17.0 and 17.1, I did not experience this error on 17.2. A list of devices I tested on is below.

Fails:

Succeeds:

This would seem to indicate that Apple fixed the problem, however that conclusion is contradicted by your bug report. Therefore, can you (1) check whether or not you get an error recognizing a simple image using the site linked below and (2) confirm that you are definitely using iOS 17.2?

https://tesseract-js-core-example.pages.dev/legacy

rin-st commented 10 months ago

@Balearica Thank you for quick response!

This would seem to indicate that Apple fixed the problem, however that conclusion is contradicted by your bug report. Therefore, can you (1) check whether or not you get an error recognizing a simple image using the site linked below and (2) confirm that you are definitely using iOS 17.2?

Sorry for confusing. I rechecked version of my device and it was 17.1.2 🤦 . I updated it to 17.2 and problem disappeared.

So to sum up. It doesn't work with oem version 0 on 17.0 and 17.1. But works on versions before 17 and 17.2+.

Thank you!

Balearica commented 10 months ago

Sorry for confusing. I rechecked version of my device and it was 17.1.2 🤦 . I updated it to 17.2 and problem disappeared.

Great, that explains the difference. Thanks for following up.

So to sum up. It doesn't work with oem version 0 on 17.0 and 17.1. But works on versions before 17 and 17.2+.

Yes, it sounds like there was a bug introduced by Apple in iOS 17.0 and fixed in 17.2. This bug impacts all versions of Tesseract.js prior to v5, and Tesseract.js v5 when run with oem values 0 (Legacy only) and 2 (LSTM + Legacy fallback).