Browse Source

uh

pull/12/head
Guillermo 10 years ago
parent
commit
7b239c67d0
  1. 3
      lib/Tesseract.js
  2. 43
      worker_src/worker.js

3
lib/Tesseract.js

@ -6,11 +6,12 @@ var Tesseract = (function(){ @@ -6,11 +6,12 @@ var Tesseract = (function(){
console.log('localhost')
var worker = new Worker(window.URL.createObjectURL(blob));
console.log(worker)
var index = 0
var handlers = []
worker.onmessage = function(e){
// console.log(handlers, e)
var handler = handlers[e.data.index]
if(e.data.progress){
handler.progress(e.data.progress)

43
worker_src/worker.js

@ -459,23 +459,36 @@ var T = (function createTesseractInstance(){ @@ -459,23 +459,36 @@ var T = (function createTesseractInstance(){
base.SetImage(Module.wrapPointer(ptr), width, height, 1, width)
base.SetRectangle(0, 0, width, height)
// base.Recognize(0);
var results = new Module.OSResults();
var success = base.DetectOS(results);
console.log('detected os successfully', !!success);
var charset = results.get_unicharset()
results.print_scores()
var best = results.get_best_result()
var oid = best.get_orientation_id(),
sid = best.get_script_id();
console.log('orientation id', oid, [0, 270, 180, 90][oid], best.get_oconfidence())
console.log('script id', sid, charset.get_script_from_script_id(sid), best.get_sconfidence())
// console.log(best)
cb(null, 'wolo')
base.End();
Module._free(ptr);
if(!success){
base.End();
Module._free(ptr);
cb("failed to detect os")
}
else {
var charset = results.get_unicharset()
console.log(charset)
// results.print_scores()
var best = results.get_best_result()
var oid = best.get_orientation_id(),
sid = best.get_script_id();
// console.log('orientation id', oid, [0, 270, 180, 90][oid], best.get_oconfidence())
// console.log('script id', sid, charset.get_script_from_script_id(sid), best.get_sconfidence())
// console.log(best)
cb(null, {
tesseract_script_id: sid,
script: charset.get_script_from_script_id(sid),
script_confidence: best.get_sconfidence(),
orientation_degrees: [0, 270, 180, 90][oid],
orientation_confidence: best.get_oconfidence()
})
base.End();
Module._free(ptr);
}
}
})
}

Loading…
Cancel
Save