|
|
@ -3,12 +3,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
exports.defaultOptions = { |
|
|
|
exports.defaultOptions = { |
|
|
|
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/', |
|
|
|
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/', |
|
|
|
workerPath: 'dist/worker.js', |
|
|
|
// workerPath: 'dist/worker.js',
|
|
|
|
|
|
|
|
workerPath: 'https://cdn.rawgit.com/naptha/tesseract.js/0.1.3/dist/worker.js', |
|
|
|
tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js' |
|
|
|
tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js' |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
exports.spawnWorker = function spawnWorker(instance, workerOptions) { |
|
|
|
exports.spawnWorker = function spawnWorker(instance, workerOptions) { |
|
|
|
var worker = new Worker(workerOptions.workerPath); |
|
|
|
if (window.Blob && window.URL) { |
|
|
|
|
|
|
|
var blob = new Blob(['importScripts("' + workerOptions.workerPath + '");']); |
|
|
|
|
|
|
|
var worker = new Worker(window.URL.createObjectURL(blob)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var worker = new Worker(workerOptions.workerPath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
worker.onmessage = function (e) { |
|
|
|
worker.onmessage = function (e) { |
|
|
|
var packet = e.data; |
|
|
|
var packet = e.data; |
|
|
|
instance._recv(packet); |
|
|
|
instance._recv(packet); |
|
|
@ -167,8 +174,13 @@ var TesseractWorker = function () { |
|
|
|
var _this = this; |
|
|
|
var _this = this; |
|
|
|
|
|
|
|
|
|
|
|
return this._delay(function (job) { |
|
|
|
return this._delay(function (job) { |
|
|
|
options = options || {}; |
|
|
|
if (typeof options === 'string') { |
|
|
|
options.lang = options.lang || 'eng'; |
|
|
|
options = { lang: options }; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
options = options || {}; |
|
|
|
|
|
|
|
options.lang = options.lang || 'eng'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
job._send('recognize', { image: image, options: options, workerOptions: _this.workerOptions }); |
|
|
|
job._send('recognize', { image: image, options: options, workerOptions: _this.workerOptions }); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|