Reputation: 1518
I have been trying to figure out how to pass in tesseract options for page segmentation. I tried tessedit_pageseg_mode: '1'
, But when I use it, the process stops at recognizing text
. If I set it as number 1, then it finishes, but the mode is still default SINGLE_BLOCK
.
I'm currently using Tesseract version: 1.0.19. But I have also tried with 2.0.0-alpha.13, but the result is same.
this.tesseract = Tesseract.create({
workerPath: '../../assets/tesseract/worker.js',
langPath: '../../assets/tesseract/trained-data',
corePath: '../../assets/tesseract/core.js',
});
this.tesseract.recognize(this.image, {
lang: 'eng',
tessedit_pageseg_mode: '1'
})
.progress((p) => {
console.log('progress', p);
this.ocrResult = p.status + ', Progress: ' + Math.round(p.progress * 100) + '%';
})
.then((data) => {
console.log(data.psm);
this.ocrResult = data.text;
}).catch((err) => {
console.error('Error occurred while recognizing text', err);
});
Any help would be appreciated. Thank you!
Update:
I kind of figured out the issue, My previous code was written line this window.Tesseract = Tesseract.create({...
but was directly using Tesseract.recognize(..
this downloaded the worker, language and core file from the internet, but was not using the provided file from the path. For some reason the file download was getting aborted when I provided the option tessedit_pageseg_mode: '1'
.
Uncaught abort() at Error at Na (https://cdn.jsdelivr.net/gh/naptha/[email protected]/index.js:36:26)
So, now I'm trying to make it use the local files by adding file:///android_asset/www
(as instructed in this blog) before in assets folder, but for some reason that's too is failing with this message
Failed to load file:///android_asset/www/assets/plugins/tesseract/worker.js: Cross origin requests are only supported for protocol schemes: http, data, chrome, https.`
Upvotes: 2
Views: 1724
Reputation: 1151
Try using localhost instead of relative path, like this:
this.tesseract = Tesseract.create({
workerPath: 'http://localhost/assets/tesseract/worker.js',
langPath: 'http://localhost/assets/tesseract/trained-data',
corePath: 'http://localhost/assets/tesseract/core.js',
});
Upvotes: 1