From 1df4b5a7526faa68e6442419d0091d50afcbc035 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Mon, 6 Jul 2015 18:19:01 -0700 Subject: [PATCH] uh --- lib/Tesseract.js | 3 ++- worker/worker.js | 43 ++++++++++++++++++++++++++++--------------- worker_src/worker.js | 43 ++++++++++++++++++++++++++++--------------- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/lib/Tesseract.js b/lib/Tesseract.js index f8f6488..f826872 100644 --- a/lib/Tesseract.js +++ b/lib/Tesseract.js @@ -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) diff --git a/worker/worker.js b/worker/worker.js index 1c776a1..f8d70b3 100644 --- a/worker/worker.js +++ b/worker/worker.js @@ -9839,23 +9839,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); + } } }) } diff --git a/worker_src/worker.js b/worker_src/worker.js index 6506469..5f99f2c 100644 --- a/worker_src/worker.js +++ b/worker_src/worker.js @@ -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); + } } }) }