Skip to content

Fixed types and docs for recognize parameters per #856 - #1073

Open
cpruijsen wants to merge 1 commit into
naptha:masterfrom
cpruijsen:fix/issue-856
Open

cpruijsen wants to merge 1 commit into
naptha:masterfrom
cpruijsen:fix/issue-856

Conversation

@cpruijsen

Copy link
Copy Markdown

Summary

  • Type RecognizeOptions as extending WorkerParams so Tesseract parameters can be passed to worker.recognize and scheduler.addJob('recognize', ...) without a type error (Fix types for setting Tesseract parameters in recognize聽#856).
  • Document that those parameters apply to a single job and are restored afterwards (unlike worker.setParameters).
  • Allow tessedit_pageseg_mode: "6" as well as PSM.SINGLE_BLOCK, matching the issue snippet.

Per-job parameters have been supported at runtime since v4 (#665): src/worker-script/index.js already splits options into Tesseract.js keys and pass-through SetVariable calls, then RestoreParameters. scheduler.addJob('recognize') is typed as Parameters<Worker['recognize']>, so fixing RecognizeOptions fixes the scheduler call site in the issue.

What I chose and the alternative

  • Chose RecognizeOptions extends WorkerParams. Alternative: only add [propName: string]: any on RecognizeOptions. That would silence the excess-property error but would not autocomplete tessedit_*. Happy to switch.
  • Chose tessedit_pageseg_mode: PSM | \${PSM}`. Alternative: keep PSMand require the enum member. The issue example uses"6"`, which TypeScript string enums reject. Happy to drop the union.

Test plan

  • scheduler.addJob('recognize', image, { tessedit_pageseg_mode: "6" }) typechecks
  • worker.recognize(image, { tessedit_pageseg_mode: PSM.SINGLE_BLOCK }) typechecks
  • worker.recognize(image, { tessedit_char_whitelist: 'Tess', rectangle: { ... } }) typechecks
  • worker.recognize with tessedit_char_whitelist in options returns the filtered text, and the next job without that option returns the full text
  • Karma / full npm test (Chrome + Firefox), not run in this change; Node mocha only

Fixes #856

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix types for setting Tesseract parameters in recognize

1 participant