Skip to content

Commit

Permalink
Fixed JSON export bugs and added new tests (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica authored Dec 26, 2024
1 parent d199d9c commit 6299aa5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"node-fetch": "^2.6.9",
"opencollective-postinstall": "^2.0.3",
"regenerator-runtime": "^0.13.3",
"tesseract.js-core": "^6.0.0-2",
"tesseract.js-core": "^6.0.0-3",
"wasm-feature-detect": "^1.2.11",
"zlibjs": "^0.3.1"
},
Expand Down
18 changes: 18 additions & 0 deletions tests/recognize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ describe('recognize()', () => {
expect(blocks[0].paragraphs[0].lines[1].text).to.be('Back \\ Slash\n');
}).timeout(TIMEOUT);

it('recongize image with multiple choices', async () => {
await workerLegacy.reinitialize('eng');
const { data: { blocks } } = await workerLegacy.recognize(`${IMAGE_PATH}/bill.png`, {}, { blocks: true });
expect(blocks[0].paragraphs[1].lines[0].words[3].choices.length).to.be(3);
expect(blocks[0].paragraphs[1].lines[0].words[3].choices[1].text).to.be('100,000.0ll');
}).timeout(TIMEOUT);

it('recongize image with multiple blocks', async () => {
// This also implicitly checks that non-text blocks are ignored,
// as otherwise the length would be 5.
await worker.reinitialize('eng');
await worker.setParameters({
tessedit_pageseg_mode: PSM.AUTO,
});
const { data: { blocks } } = await worker.recognize(`${IMAGE_PATH}/bill.png`, {}, { blocks: true });
expect(blocks.length).to.be(4);
}).timeout(TIMEOUT);

it('recongize chinese image', async () => {
await worker.reinitialize('chi_tra');
const { data: { blocks } } = await worker.recognize(`${IMAGE_PATH}/chinese.png`, {}, { blocks: true });
Expand Down

0 comments on commit 6299aa5

Please sign in to comment.