Comments (5)
Edit: This explanation is not the root cause for this user, however it may be useful for other users experiencing an 'out of memory' error. See comments below.
Copying the code from the JSFiddle below for the benefit of other users, as opening will indeed freeze/crash the page.
let worker
let i=0;
const x = 50;
const image = document.querySelector('img');
async function OCRImageByTesseract() {
i++;
if (i%x==0) {
worker = worker || await Tesseract.createWorker('eng');
const result = await worker.recognize(image.src);
console.log(i/x, result)
}
requestAnimationFrame(OCRImageByTesseract)
}
// loop start;
requestAnimationFrame(OCRImageByTesseract);
Short answer: I believe this would be resolved by switching to using a scheduler rather than using worker.recognize
. The basic syntax for schedulers is explained here, and there is a scheduler example in the examples directory.
Longer answer: I believe this issue is due to the fact that this code sends new jobs to the worker before the previous job is completed. Workers have no mechanism for queuing jobs--workers were written with the assumption that a new worker.recognize
function would not be run until the previous call to worker.recognize
completed. Support for running jobs asynchronously and/or in parallel was added later with the addition of schedulers. As a result, Tesseract.js behaves in unexpected and undesirable ways when this is not the case. This was recently discussed in #875.
from tesseract.js.
You're right, my original explanation was incorrect. I was unfamiliar with the requestAnimationFrame
function, however it looks like calling that function is the equivalent of just calling OCRImageByTesseract
once. Therefore, this snippet is waiting for worker.recognize
to finish before running it again.
I do not know why this code is causing the page to crash in JSFiddle, however I now suspect the issue is with JSFiddle rather than Tesseract.js. I was unable to replicate this issue outside of JSFiddle, even when copy/pasting the exact code from the JSFiddle that crashes.
If you are able to replicate this problem using a standard web server, please create a repo with a reproducible example, or alternatively paste an HTML snippet that can be run as a single-file site, and I can look into it further. If the issue cannot be replicated anywhere outside of JSFiddle, then the issue should be raised with that project.
from tesseract.js.
I checked same code on CodePen, but this issue cannot be reproducible.
So this might be depends on JSFiddle as you suspected.
from tesseract.js.
Thank you @Balearica
Let me confirm one thing.
Doesn't the below code using await
wait until finishing worker.recognize
though the return value is assigned to result
?
const result = await worker.recognize(image.src);
What I want to do is just executing worker.recognize
repeatedly, not parallel execution.
from tesseract.js.
Thank you @Balearica !
I will check if the issue can be reproducible except on JSFiddle
from tesseract.js.
Related Issues (20)
- Worker stuck on "loading language traineddata" HOT 4
- Updated types to infer output formats
- Inference of Chinese handwritten characters is bad HOT 3
- Add line size metrics (ascender, descender, size) to `line` objects in `blocks` output HOT 1
- Font attributes incorrect even when font is properly identified (`is_italic`, `is_serif`, etc.) HOT 1
- Focusing area HOT 1
- Multiple issues: Discussion
- Disable non-text output formats by default
- Tesseract - Running in Browser Console HOT 1
- Error: Network error while fetching HOT 1
- how to use installed tessercat lib on windows for tesseract.js? HOT 1
- createWorker throws exception with option.langPath set in electron HOT 7
- Auto fill forms by scanning ID cards
- Suppressing "Corrupt JPEG data: 1 extraneous bytes before marker 0xd9" output HOT 3
- Tesseract.js Bug on IBM i Server HOT 9
- Legacy model does not work for indic and arabic scripts due to Legacy data being removed
- Combine worker and scheduler interfaces
- Issue with Tesseract.js OCR Integration in Angular Application HOT 5
- Rectangles not working, pure white image interpreted as tildes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tesseract.js.