Browse Source

Merge branch 'develop' of ssh://fcoe-dev.deltaww.com:443/jerry.wu/tesseract.js into develop

develop
Jerome Wu 6 years ago
parent
commit
08be88c890
  1. 0
      examples/browser/basic.html
  2. 0
      examples/browser/demo.html
  3. 1
      examples/file-input/README.md
  4. 18
      examples/node/basic.js
  5. 7
      examples/node/detect.js
  6. 23
      examples/node/recognize.js
  7. 12
      src/common/workerUtils.js

0
examples/file-input/basic.html → examples/browser/basic.html

0
examples/file-input/demo.html → examples/browser/demo.html

1
examples/file-input/README.md

@ -1 +0,0 @@ @@ -1 +0,0 @@
#

18
examples/node/basic.js

@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
// replace this with require('tesseract.js')
const path = require('path');
const { TesseractWorker } = require('../../');
const image = path.resolve(__dirname, '../../tests/assets/images/cosmic.png');
const tessWorker = new TesseractWorker();
tessWorker.recognize(image)
.then((data) => {
console.log('then\n', data.text);
})
.catch((err) => {
console.log('catch\n', err);
})
.finally(() => {
console.log('finally\n');
process.exit();
});

7
examples/node/detect.js

@ -1,10 +1,13 @@ @@ -1,10 +1,13 @@
// replace this with require('tesseract.js')
#!/usr/bin/env node
const path = require('path');
const { TesseractWorker } = require('../../');
const image = path.resolve(__dirname, '../../tests/assets/images/cosmic.png');
const [,, imagePath] = process.argv;
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png'));
const tessWorker = new TesseractWorker();
console.log(`Detecting ${image}`);
tessWorker.detect(image)
.progress((info) => {
console.log(info);

23
examples/node/recognize.js

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
#!/usr/bin/env node
const path = require('path');
const { TesseractWorker } = require('../../');
const [,, imagePath] = process.argv;
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png'));
const tessWorker = new TesseractWorker();
console.log(`Recognizing ${image}`);
tessWorker.recognize(image)
.progress((info) => {
console.log(info);
})
.then((data) => {
console.log(data.text);
})
.catch((err) => {
console.log('Error\n', err);
})
.finally(() => {
process.exit();
});

12
src/common/workerUtils.js

@ -173,19 +173,19 @@ const handleDetect = ({ @@ -173,19 +173,19 @@ const handleDetect = ({
TessModule._free(ptr);
res.reject('Failed to detect OS');
} else {
const best = results.get_best_result();
const oid = best.get_orientation_id();
const sid = best.get_script_id();
const best = results.best_result;
const oid = best.orientation_id;
const sid = best.script_id;
api.End();
TessModule._free(ptr);
res.resolve({
tesseract_script_id: sid,
script: results.get_unicharset().get_script_from_script_id(sid),
script_confidence: best.get_sconfidence(),
script: results.unicharset.get_script_from_script_id(sid),
script_confidence: best.sconfidence,
orientation_degrees: [0, 270, 180, 90][oid],
orientation_confidence: best.get_oconfidence(),
orientation_confidence: best.oconfidence,
});
}
})

Loading…
Cancel
Save