tesseract.js icon indicating copy to clipboard operation
tesseract.js copied to clipboard

Is there a way to return multiple results for a single word?

Open bitsandbytes opened this issue 3 years ago • 2 comments

I'm trying out tesseract.js for Chinese handwriting recognition, and am currently receiving a single result for each word. But, given the complexity of the words I would like to receive more potential results for users to choose their most similar result. Is this possible?

The API supports multiple results but I'm unclear if that's to return results when there are multiple words/characters sent in - a line of text that parses into 10 words, for example, or if I should be able to send in a single Chinese word and receive tesseract's first 10 guesses for that character.

Would creating multiple workers, or running "recognize" multiple times return different results?

I believe this is fairly boilerplate, and the single result I receive is the same as what the tesseract.js demo returns.

const { createWorker } = Tesseract;
const worker = createWorker({
    corePath: '/tesseract/tesseract-core.wasm.js',
    langPath: '/tesseract/lang-data',
    workerPath: '/tesseract/worker.min.js',
    errorHandler: (error: string) => {
      console.error(`Caught error in OCR: ${error}`);
    },
    logger: displayOcrStatus // console.log for all progress
});

await worker.load();
await worker.loadLanguage(language); // sending in chi_sim+chi_sim_vert
await worker.initialize(language);
const {
  data: { text }
} = await worker.recognize(image); // a Canvas
displayOcrText(text);

await worker.terminate();

Thanks!

bitsandbytes avatar Apr 08 '22 13:04 bitsandbytes

To clarify, I am getting multiple results back, just not as many as I was expecting. There are examples that received at most 1-3 choices, so I was thinking there must be many more results with less confidence that it could be returning.

bitsandbytes avatar Apr 08 '22 14:04 bitsandbytes

I agree with your intuition regarding not enough options being reported, however as I've had similar thoughts using the command line version of Tesseract (only in English though), I think it's a behavior of the Tesseract library rather than anything implemented in the tesseract.js interface.

If you want 2 distinct options, I would recommend running recognition once with Tesseract Legacy and once with Tesseract LSTM. These engines take entirely different approaches to recognition, so should provide unique results.

Balearica avatar Aug 06 '22 22:08 Balearica

Closing as answered.

Balearica avatar Nov 25 '22 20:11 Balearica