Browse Source

uh

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

3
lib/Tesseract.js

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

43
worker/worker.js

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

43
worker_src/worker.js

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