Pure Javascript OCR for more than 100 Languages 📖🎉🖥
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const { createWorker, createScheduler } = require('../../');
|
|
|
|
|
|
|
|
const scheduler = createScheduler();
|
|
|
|
|
|
|
|
// Creates worker and adds to scheduler
|
|
|
|
const workerGen = async () => {
|
|
|
|
const worker = await createWorker({cachePath: "."});
|
|
|
|
await worker.loadLanguage('eng');
|
|
|
|
await worker.initialize('eng');
|
|
|
|
scheduler.addWorker(worker);
|
|
|
|
}
|
|
|
|
|
|
|
|
const workerN = 4;
|
|
|
|
(async () => {
|
|
|
|
const resArr = Array(workerN);
|
|
|
|
for (let i=0; i<workerN; i++) {
|
|
|
|
resArr[i] = await workerGen();
|
|
|
|
}
|
|
|
|
await Promise.all(resArr);
|
|
|
|
/** Add 4 recognition jobs */
|
|
|
|
const results = await Promise.all(Array(10).fill(0).map(() => (
|
|
|
|
scheduler.addJob('recognize', 'https://tesseract.projectnaptha.com/img/eng_bw.png').then((x) => console.log(x.data.text))
|
|
|
|
)))
|
|
|
|
await scheduler.terminate(); // It also terminates all workers.
|
|
|
|
})();
|