Browse Source

Update example/recognize.js

pull/427/head
Jerome Wu 5 years ago
parent
commit
c5935b2636
  1. 18
      examples/node/recognize.js

18
examples/node/recognize.js

@ -1,13 +1,23 @@ @@ -1,13 +1,23 @@
#!/usr/bin/env node
const path = require('path');
const Tesseract = require('../../');
const { createWorker } = require('../../');
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),
});
Tesseract.recognize(image, 'eng', { logger: m => console.log(m) })
.then(({ data: { text } }) => {
console.log(text);
(async () => {
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
await worker.setParameters({
user_defined_dpi: '300',
});
const { data: { text } } = await worker.recognize(image);
console.log(text);
await worker.terminate();
})();

Loading…
Cancel
Save