我一直试图找出如何传递用于页面分割的tesseract选项。我尝试了tessedit_pageseg_mode: '1'
,但是当我使用它时,这个过程会在recognizing text
停止。如果我把它设置为1号,那么它就完成了,但是模式仍然是默认的SINGLE_BLOCK
。
我目前正在使用Tesseract版本:1.0.19。但是我也尝试过使用2.0.0-alpha.13,,但是结果是一样的。
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);
});
任何帮助都将不胜感激。谢谢!
更新:I指出了这个问题,我之前的代码是在window.Tesseract = Tesseract.create({...
中写的,但是直接使用的是Tesseract.recognize(..
--从互联网上下载了工人、语言和核心文件,但是没有使用路径中提供的文件。由于某些原因,当我提供选项tessedit_pageseg_mode: '1'
时,文件下载被中止。
在Na (https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js:36:26)处发生错误时的未捕获中止()
所以,现在我试图让它使用本地文件,在资产文件夹中添加file:///android_asset/www
(按照本博客的指示),但是由于某种原因,这个消息也失败了。
未能加载file:///android_asset/www/assets/plugins/tesseract/worker.js:跨源请求仅支持协议方案: http、data、chrome、http。
发布于 2019-08-23 20:30:31
尝试使用localhost而不是相对路径,如下所示:
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',
});
https://stackoverflow.com/questions/57627738
复制相似问题