Hello,
i'm trying to get an OCR function into my blazor website. Therefore i have a js-File(ocr.js) that is creating a Worker that should recognize the image. The paths are all correct.
My Website is using https with a selfsigned certificate.
Like this, everything works as long as i'm online, but i want the same functions, when i dont have any internet-Connection. So i tried to add all path for the worker local.
Code File ocr.js:
var worker = null;
var ocrobject = "ocrobject";
/* call function work to create text using chosen image */
async function imageToText(Image) {
worker = Tesseract.createWorker({
workerPath: 'lib/tesseract.js/worker.min.js',
langPath: /*'source/tessdata/',*/ 'lib/tesseract.js',
corePath: 'lib/tesseract.js/tesseract-core.wasm.js',
/*add logger here*/
logger: m => console.log(m)
});
Tesseract.setLogging(true);
await work(Image);
}
/*function to create text from given image, using whitelist to specify which characters are allow in the return text*/
async function work(img) {
await worker.load();
await worker.loadLanguage('deu');
await worker.initialize('deu');
await worker.setParameters({
tessedit_char_whitelist: '0123456789+()&|/\.-:@abcdefghijklmnopqrstuvwxyzäöüßABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ ',
});
let result = await worker.detect(img);
console.log(result.data);
result = await worker.recognize(img);
let line = result.data.lines.map(e => e.text);
console.log(line);
let lineJson = JSON.stringify(line);
sessionStorage.setItem(ocrobject, lineJson);
await worker.terminate();
}
/*Source: github.com/naptha/tesseract.js*/ Now i'm getting this error when i'm trying to use the function "imageToText", when i'm offline:
Uncaught Error: TypeError: Failed to fetch
at createWorker.js:173:15
at e.onmessage (onMessage.js:3:5)
createworker.js is called in the file "tesseract.min.js.map".
Do i need to add more Files to my project so that tesseract can work offline?Or do i need to change the "tesseract.min.js"/"tesseract.min.js.map"?
The files i already have you can see in the Image "Solution Explorer".
Windows 10
VS19
.NET 5.0
Thanks to everyone that is trying to help