Browse Source

choosing memory usage dynamically

pull/34/head
Kevin Kwok 8 years ago
parent
commit
ea54eaa23f
  1. 1
      .gitignore
  2. 4
      examples/node/basic.js
  3. 16
      src/common/worker.js

1
.gitignore vendored

@ -3,3 +3,4 @@ node_modules/* @@ -3,3 +3,4 @@ node_modules/*
yarn.lock
tesseract.dev.js
worker.dev.js
*.traineddata

4
examples/node/basic.js

@ -9,6 +9,6 @@ Tesseract.recognize(image) @@ -9,6 +9,6 @@ Tesseract.recognize(image)
.catch(err => {
console.log('catch\n', err);
})
.finally(data => {
console.log('finally\n', data.text);
.finally(e => {
console.log('finally\n');
});

16
src/common/worker.js

@ -18,11 +18,15 @@ function dispatchHandlers(packet, send){ @@ -18,11 +18,15 @@ function dispatchHandlers(packet, send){
latestJob = respond;
try {
if(packet.action === 'recognize'){
handleRecognize(packet.payload, respond)
}else if(packet.action === 'detect'){
handleDetect(packet.payload, respond)
}
} catch (err) {
respond.reject(err)
}
}
exports.dispatchHandlers = dispatchHandlers;
@ -32,17 +36,25 @@ exports.setAdapter = function setAdapter(impl){ @@ -32,17 +36,25 @@ exports.setAdapter = function setAdapter(impl){
function handleInit(req, res){
if(!Module){
var MIN_MEMORY = 100663296;
if(['chi_sim', 'chi_tra', 'jpn'].indexOf(req.options.lang) != -1){
MIN_MEMORY = 167772160;
}
if(!Module || Module.TOTAL_MEMORY < MIN_MEMORY){
var Core = adapter.getCore(req, res);
res.progress({ status: 'initializing tesseract', progress: 0 })
Module = Core({
TOTAL_MEMORY: req.memory,
TOTAL_MEMORY: MIN_MEMORY,
TesseractProgress(percent){
latestJob.progress({ status: 'recognizing text', progress: Math.max(0, (percent-30)/70) })
},
onRuntimeInitialized() {}
})
Module.FS_createPath("/", "tessdata", true, true)
base = new Module.TessBaseAPI()
res.progress({ status: 'initializing tesseract', progress: 1 })

Loading…
Cancel
Save