@ -2,8 +2,8 @@ var input = document.getElementById('input')
@@ -2,8 +2,8 @@ var input = document.getElementById('input')
var input _overlay = document . getElementById ( 'input-overlay' )
var ioctx = input _overlay . getContext ( '2d' )
// var output = document.getElementById('output')
var output _overlay = document . getElementById ( 'output-overlay' )
var output _text = document . getElementById ( 'output-text ' )
// var output_overlay = document.getElementById('output-overlay')
var output _text = document . getElementById ( 'log ' )
var demo _instructions = document . getElementById ( 'demo-instructions' )
@ -28,6 +28,8 @@ var lang_drop_instructions = {
@@ -28,6 +28,8 @@ var lang_drop_instructions = {
function setUp ( ) {
input _overlay . width = input . naturalWidth
input _overlay . height = input . naturalHeight
output _text . style . height = input . height + 'px'
}
setUp ( )
@ -47,7 +49,7 @@ function startDemo(){
@@ -47,7 +49,7 @@ function startDemo(){
function start ( ) {
Tesseract . recognize ( input )
. progress ( progress )
. progress ( progressUpdate )
. then ( result )
input . removeEventListener ( 'load' , start )
@ -57,25 +59,64 @@ function startDemo(){
@@ -57,25 +59,64 @@ function startDemo(){
else input . addEventListener ( 'load' , start )
}
function progress ( p ) {
var text = JSON . stringify ( p )
// function progress(p){
// var text = JSON.stringify(p)
// octx.clearRect(0, 0, output.width, output.height)
// // octx.clearRect(0, 0, output.width, output.height)
// // octx.textAlign = 'center'
// // octx.fillText(text, output.width/2, output.height/2)
// output_overlay.style.display = 'block'
// output_overlay.innerHTML += output_overlay.innerHTML.length ? "\n" + text : text
// output_overlay.scrollTop = output_overlay.scrollHeight;
// }
function progressUpdate ( packet ) {
var log = document . getElementById ( 'log' ) ;
if ( log . firstChild && log . firstChild . status === packet . status ) {
if ( 'progress' in packet ) {
var progress = log . firstChild . querySelector ( 'progress' )
progress . value = packet . progress
}
} else {
var line = document . createElement ( 'div' ) ;
line . status = packet . status ;
var status = document . createElement ( 'div' )
status . className = 'status'
status . appendChild ( document . createTextNode ( packet . status ) )
line . appendChild ( status )
if ( 'progress' in packet ) {
var progress = document . createElement ( 'progress' )
progress . value = packet . progress
progress . max = 1
line . appendChild ( progress )
}
if ( packet . status == 'done' ) {
var pre = document . createElement ( 'pre' )
pre . appendChild ( document . createTextNode ( packet . data . text ) )
line . innerHTML = ''
line . appendChild ( pre )
}
// octx.textAlign = 'center'
// octx.fillText(text, output.width/2, output.height/2)
output _overlay . style . display = 'block'
output _overlay . innerHTML += output _overlay . innerHTML . length ? "\n" + text : text
output _overlay . scrollTop = output _overlay . scrollHeight ;
log . insertBefore ( line , log . firstChild )
}
}
function result ( res ) {
// octx.clearRect(0, 0, output.width, output.height)
// octx.textAlign = 'left'
console . log ( 'result was:' , res )
output _overlay . style . display = 'none'
output _text . innerHTML = res . text
console . log ( 'result was:' , res )
// output_overlay.style.display = 'none'
// output_text.innerHTML = res.text
progressUpdate ( { status : 'done' , data : res } )
res . words . forEach ( function ( w ) {
var b = w . bbox ;
@ -129,10 +170,10 @@ function play(){
@@ -129,10 +170,10 @@ function play(){
demo _instructions . style . display = 'none'
output _text . style . display = 'block'
output _text . innerHTML = ''
output _overlay . innerHTML = ''
// output_overlay.innerHTML = ''
Tesseract . recognize ( input , language )
. progress ( progress )
. progress ( progressUpdate )
. then ( result )
}