Browse Source

Reworked createWorker to be async and throw errors per #654

dev/v4
Balearica 2 years ago
parent
commit
b87afe9d93
  1. 4
      examples/node/benchmark.js
  2. 3
      examples/node/download-pdf.js
  3. 7
      examples/node/recognize.js

4
examples/node/benchmark.js

@ -2,10 +2,8 @@ @@ -2,10 +2,8 @@
const path = require('path');
const { createWorker } = require('../../');
const worker = createWorker();
(async () => {
await worker.load();
const worker = await createWorker();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const fileArr = ["../data/meditations.jpg", "../data/tyger.jpg", "../data/testocr.png"];

3
examples/node/download-pdf.js

@ -9,8 +9,7 @@ const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/c @@ -9,8 +9,7 @@ const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/c
console.log(`Recognizing ${image}`);
(async () => {
const worker = createWorker();
await worker.load();
const worker = await createWorker();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(image);

7
examples/node/recognize.js

@ -6,12 +6,11 @@ const [,, imagePath] = process.argv; @@ -6,12 +6,11 @@ const [,, imagePath] = process.argv;
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png'));
console.log(`Recognizing ${image}`);
const worker = createWorker({
logger: m => console.log(m),
});
(async () => {
await worker.load();
const worker = await createWorker({
logger: m => console.log(m),
});
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(image);

Loading…
Cancel
Save