Skip to content

Commit

Permalink
fix worker code for tesseractjs
Browse files Browse the repository at this point in the history
  • Loading branch information
lublak committed Mar 19, 2024
1 parent c5aeb7f commit 08c2cf9
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/tesseractjsocr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ export class TesseractJsOcr implements OcrApi {
if (buffers.length == 0) return [];
if (buffers.length == 1) {
const lang: string = langs.join('+');
const worker: Worker = createWorker();
await worker.load();
await worker.loadLanguage(lang);
await worker.initialize(lang);
const worker: Worker = await createWorker(lang);
const data: RecognizeResult = await worker.recognize(buffers[0]);
await worker.terminate();
return [data.data.text];
}
const lang: string = langs.join('+');
const scheduler: Scheduler = createScheduler();
for (let i: number = 0; i < buffers.length; i++) {
const worker: Worker = createWorker();
await worker.load();
await worker.loadLanguage(lang);
await worker.initialize(lang);
const worker: Worker = await createWorker(lang);
scheduler.addWorker(worker);
}
const result: RecognizeResult[] = await Promise.all(buffers.map(async (buffer: Buffer) => scheduler.addJob('recognize', buffer))) as RecognizeResult[];
Expand Down

0 comments on commit 08c2cf9

Please sign in to comment.