diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2025-06-13 23:28:57 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2025-06-13 23:28:57 +0530 |
| commit | 7164ef595147d997068b953d0e8bd19add0db5f9 (patch) | |
| tree | 415a297d71c7ef93c5bc38d071b8870d01020fa2 /src | |
| parent | 64e38ab240a1ca3427592eb80f2cef57fddbdafe (diff) | |
| download | banglar-bhumi-utils-7164ef595147d997068b953d0e8bd19add0db5f9.tar.gz banglar-bhumi-utils-7164ef595147d997068b953d0e8bd19add0db5f9.zip | |
Using es-modules for webpack configuration.
Diffstat (limited to 'src')
| -rw-r--r-- | src/background/run-ocr.ts | 34 | ||||
| -rw-r--r-- | src/offscreen.json | 3 | ||||
| -rw-r--r-- | src/offscreen/ocr.ts | 1 |
3 files changed, 35 insertions, 3 deletions
diff --git a/src/background/run-ocr.ts b/src/background/run-ocr.ts index f6d1339..1bf605b 100644 --- a/src/background/run-ocr.ts +++ b/src/background/run-ocr.ts @@ -1,13 +1,41 @@ import Tesseract from "tesseract.js"; +// +// chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { +// if (message.type === "OCR") { +// (async () => { +// const { data: { text, confidence } } = await Tesseract.recognize(message.dataURL, "eng+osd", { +// logger: m => console.log(m), +// }); +// sendResponse({ text, confidence }); +// })(); +// return true; +// } +// +// return false; +// }); chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.type === "OCR") { (async () => { - const { data: { text, confidence } } = await Tesseract.recognize(message.dataURL, "eng+osd", { - logger: m => console.log(m), + console.log(message); + const worker = await Tesseract.createWorker("eng", 1, { + workerBlobURL: false, + logger: console.log, }); - sendResponse({ text, confidence }); + + await worker.setParameters({ + tessedit_char_whitelist: "ABCDEFGHJKLMNPQRSTUVWXYZ23456789", + }); + + const { + data: { text, confidence } + } = await worker.recognize(message.dataURL); + + await worker.terminate(); + + sendResponse({ type: "OCR_RESULT", text, confidence }); })(); + return true; } diff --git a/src/offscreen.json b/src/offscreen.json new file mode 100644 index 0000000..3159170 --- /dev/null +++ b/src/offscreen.json @@ -0,0 +1,3 @@ +[ + "ocr.ts" +] diff --git a/src/offscreen/ocr.ts b/src/offscreen/ocr.ts new file mode 100644 index 0000000..c645b9f --- /dev/null +++ b/src/offscreen/ocr.ts @@ -0,0 +1 @@ +console.log("THIS IS OFFSCREEN DOCUMENT!"); |
