Skip to content

Commit 6299aa5

Browse files
authored
Fixed JSON export bugs and added new tests (#987)
1 parent d199d9c commit 6299aa5

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"node-fetch": "^2.6.9",
6969
"opencollective-postinstall": "^2.0.3",
7070
"regenerator-runtime": "^0.13.3",
71-
"tesseract.js-core": "^6.0.0-2",
71+
"tesseract.js-core": "^6.0.0-3",
7272
"wasm-feature-detect": "^1.2.11",
7373
"zlibjs": "^0.3.1"
7474
},

tests/recognize.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ describe('recognize()', () => {
286286
expect(blocks[0].paragraphs[0].lines[1].text).to.be('Back \\ Slash\n');
287287
}).timeout(TIMEOUT);
288288

289+
it('recongize image with multiple choices', async () => {
290+
await workerLegacy.reinitialize('eng');
291+
const { data: { blocks } } = await workerLegacy.recognize(`${IMAGE_PATH}/bill.png`, {}, { blocks: true });
292+
expect(blocks[0].paragraphs[1].lines[0].words[3].choices.length).to.be(3);
293+
expect(blocks[0].paragraphs[1].lines[0].words[3].choices[1].text).to.be('100,000.0ll');
294+
}).timeout(TIMEOUT);
295+
296+
it('recongize image with multiple blocks', async () => {
297+
// This also implicitly checks that non-text blocks are ignored,
298+
// as otherwise the length would be 5.
299+
await worker.reinitialize('eng');
300+
await worker.setParameters({
301+
tessedit_pageseg_mode: PSM.AUTO,
302+
});
303+
const { data: { blocks } } = await worker.recognize(`${IMAGE_PATH}/bill.png`, {}, { blocks: true });
304+
expect(blocks.length).to.be(4);
305+
}).timeout(TIMEOUT);
306+
289307
it('recongize chinese image', async () => {
290308
await worker.reinitialize('chi_tra');
291309
const { data: { blocks } } = await worker.recognize(`${IMAGE_PATH}/chinese.png`, {}, { blocks: true });

0 commit comments

Comments
 (0)