Browse Source

Add preserve interword spaces test case

develop
Jerome Wu 5 years ago
parent
commit
93186a5dc7
  1. 22
      examples/node/preserve-interword-spaces.js
  2. 5
      package.json
  3. BIN
      tests/assets/images/bill.png
  4. 4
      tests/constants.js
  5. 11
      tests/recognize.test.js

22
examples/node/preserve-interword-spaces.js

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const { createWorker } = require('../../');
const [,, imagePath] = process.argv;
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/bill.png'));
console.log(`Recognizing ${image}`);
(async () => {
const worker = createWorker();
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
await worker.setParameters({
preserve_interword_spaces: '1',
});
const { data: { text } } = await worker.recognize(image);
console.log(JSON.stringify({ text }));
await worker.terminate();
})();

5
package.json

@ -12,8 +12,9 @@ @@ -12,8 +12,9 @@
"prepublishOnly": "npm run build",
"wait": "rimraf dist && wait-on http://localhost:3000/dist/tesseract.dev.js",
"test": "npm-run-all -p -r start test:all",
"test:all": "npm-run-all wait test:browser:* test:node",
"test:node": "nyc mocha --exit --bail --require ./scripts/test-helper.js ./tests/*.test.js",
"test:all": "npm-run-all wait test:browser:* test:node:all",
"test:node": "nyc mocha --exit --bail --require ./scripts/test-helper.js",
"test:node:all": "npm run test:node:one -- ./tests/*.test.js",
"test:browser-tpl": "mocha-headless-chrome -a incognito -a no-sandbox -a disable-setuid-sandbox -a disable-logging -t 300000",
"test:browser:detect": "npm run test:browser-tpl -- -f ./tests/detect.test.html",
"test:browser:recognize": "npm run test:browser-tpl -- -f ./tests/recognize.test.html",

BIN
tests/assets/images/bill.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

4
tests/constants.js

File diff suppressed because one or more lines are too long

11
tests/recognize.test.js

@ -81,6 +81,17 @@ describe('recognize()', () => { @@ -81,6 +81,17 @@ describe('recognize()', () => {
));
});
describe('should work with selected parameters', () => {
it('support preserve_interword_spaces', async () => {
await worker.initialize('eng');
await worker.setParameters({
preserve_interword_spaces: '1',
});
const { data: { text } } = await worker.recognize(`${IMAGE_PATH}/bill.png`);
expect(text).to.be(BILL_SPACED_TEXT);
}).timeout(TIMEOUT);
});
describe('should support all page seg modes', () => {
Object
.keys(PSM)

Loading…
Cancel
Save