Tesseract 无法加载任何语言(节点 tesseract.js)
Tesseract couldn't load any languages (node tesseract.js)
我 运行 npm install tesseract.js
现在我尝试 运行 这个代码:
const Tesseract = require('tesseract.js');
const filename = 'Screen Shot 2018-01-13 at 16.51.06.png';
Tesseract.recognize(filename)
.progress(p => {
console.log('progress', p)
}).catch(err =>
console.error(err)
).then(result => {
console.log(result.text);
process.exit(0);
});
很简单,Screen Shot 2018-01-13 at 16.51.06.png
是同目录下的文字图片
此代码输出:
progress { status: 'loading tesseract core' }
progress { status: 'loaded tesseract core' }
progress { status: 'initializing tesseract', progress: 0 }
pre-main prep time: 54 ms
progress { status: 'initializing tesseract', progress: 1 }
progress { status: 'loading eng.traineddata', progress: 0 }
progress { status: 'loading eng.traineddata', progress: 1 }
progress { status: 'initializing api', progress: 0 }
Failed loading language 'eng'
Tesseract couldn't load any languages!
progress { status: 'initializing api', progress: 0.3 }
progress { status: 'initializing api', progress: 0.6 }
progress { status: 'initializing api', progress: 1 }
progress { status: 'recognizing text', progress: 0 }
AdaptedTemplates != NULL:Error:Assert failed:in file ../classify/adaptmatch.cpp, line 190
/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:4
function f(a){throw a;}var h=void 0,i=!0,j=null,k=!1;function aa(){return function(){}}function ba(a){return function(){return a}}var n,Module;Module||(Module=eval("(function() { try { return TesseractCore || {} } catch(e) { return {} } })()"));var ca={},da;for(da in Module)Module.hasOwnProperty(da)&&(ca[da]=Module[da]);var ea=i,fa=!ea&&i;
^
abort() at Error
at Na (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:32:26)
at Object.ka [as abort] (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:507:108)
at _abort (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:373:173)
at $L (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:383:55709)
at jpa (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:388:22274)
at lT (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:80568)
at mT (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:80700)
at Array.BS (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:69011)
at bP (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:383:110121)
at jT (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:80280)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.
为了比较,这里是常规的 tesseract 命令(使用自制软件安装):
$ tesseract 'Screen Shot 2018-01-13 at 16.51.06.png' stdout
Warning. Invalid resolution 0 dpi. Using 70 instead.
Do you like anyone?
Um, I have a bf
Delivered
Ohh haha
如何让 tesseract.js 工作?
引用 GitHub:
I was able to get this working by downloading the trained language data for the language I need from here. Unzip the file and put it somewhere in your solution. Then the call to Tesseract will look something like the below. You probably want to save a reference to what is returned by create because loading the file takes some time.
var tesseractPromise = tesseract.create({ langPath: "eng.traineddata" }).recognize(imagePath, 'eng');
eng.traineddata
必须进入根文件夹,或与调用节点脚本相同的目录。
我 运行 npm install tesseract.js
现在我尝试 运行 这个代码:
const Tesseract = require('tesseract.js');
const filename = 'Screen Shot 2018-01-13 at 16.51.06.png';
Tesseract.recognize(filename)
.progress(p => {
console.log('progress', p)
}).catch(err =>
console.error(err)
).then(result => {
console.log(result.text);
process.exit(0);
});
很简单,Screen Shot 2018-01-13 at 16.51.06.png
是同目录下的文字图片
此代码输出:
progress { status: 'loading tesseract core' }
progress { status: 'loaded tesseract core' }
progress { status: 'initializing tesseract', progress: 0 }
pre-main prep time: 54 ms
progress { status: 'initializing tesseract', progress: 1 }
progress { status: 'loading eng.traineddata', progress: 0 }
progress { status: 'loading eng.traineddata', progress: 1 }
progress { status: 'initializing api', progress: 0 }
Failed loading language 'eng'
Tesseract couldn't load any languages!
progress { status: 'initializing api', progress: 0.3 }
progress { status: 'initializing api', progress: 0.6 }
progress { status: 'initializing api', progress: 1 }
progress { status: 'recognizing text', progress: 0 }
AdaptedTemplates != NULL:Error:Assert failed:in file ../classify/adaptmatch.cpp, line 190
/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:4
function f(a){throw a;}var h=void 0,i=!0,j=null,k=!1;function aa(){return function(){}}function ba(a){return function(){return a}}var n,Module;Module||(Module=eval("(function() { try { return TesseractCore || {} } catch(e) { return {} } })()"));var ca={},da;for(da in Module)Module.hasOwnProperty(da)&&(ca[da]=Module[da]);var ea=i,fa=!ea&&i;
^
abort() at Error
at Na (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:32:26)
at Object.ka [as abort] (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:507:108)
at _abort (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:373:173)
at $L (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:383:55709)
at jpa (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:388:22274)
at lT (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:80568)
at mT (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:80700)
at Array.BS (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:69011)
at bP (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:383:110121)
at jT (/Users/George/Documents/Projects/ssm-bot/node_modules/tesseract.js-core/index.js:387:80280)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.
为了比较,这里是常规的 tesseract 命令(使用自制软件安装):
$ tesseract 'Screen Shot 2018-01-13 at 16.51.06.png' stdout
Warning. Invalid resolution 0 dpi. Using 70 instead.
Do you like anyone?
Um, I have a bf
Delivered
Ohh haha
如何让 tesseract.js 工作?
引用 GitHub:
I was able to get this working by downloading the trained language data for the language I need from here. Unzip the file and put it somewhere in your solution. Then the call to Tesseract will look something like the below. You probably want to save a reference to what is returned by create because loading the file takes some time.
var tesseractPromise = tesseract.create({ langPath: "eng.traineddata" }).recognize(imagePath, 'eng');
eng.traineddata
必须进入根文件夹,或与调用节点脚本相同的目录。