@ -5,19 +5,29 @@ var output = document.getElementById('output')
var octx = output . getContext ( '2d' )
var octx = output . getContext ( '2d' )
var language = 'eng'
var language = 'eng'
var demoStarted = false
var demoStarted = false
var options = [ ] . slice . call ( document . querySelectorAll ( '.option' ) )
var lang _demo _images = {
eng : 'img/eng_bw.png' ,
chi _sim : 'img/chi_sim.png' ,
rus : 'img/rus.png' ,
}
function setUp ( ) {
output . width = input . naturalWidth
output . height = input . naturalHeight
output . width = input . naturalWidth
output . style . width = input . offset Width
output . height = input . naturalHeight
output . style . height = input . offset Height
output . style . width = input . offsetWidth
input _overlay . width = input . natural Width
output . style . height = input . offset Height
input _overlay . height = input . natural Height
input _overlay . width = input . naturalWidth
input _overlay . style . width = input . offsetWidth
input _overlay . height = input . naturalHeight
input _overlay . style . height = input . offsetHeight
}
input _overlay . style . width = input . offsetWidth
setUp ( )
input _overlay . style . height = input . offsetHeight
input . onload = setUp ( )
function isOutputVisible ( ) {
function isOutputVisible ( ) {
@ -28,11 +38,17 @@ function startDemoIfVisible(argument) {
if ( isOutputVisible ( ) && ! demoStarted ) startDemo ( ) ;
if ( isOutputVisible ( ) && ! demoStarted ) startDemo ( ) ;
}
}
function makeGoodOutputFont ( ) {
octx . font = '20px Times' ;
octx . font = . 8 * output . width * 20 / octx . measureText ( 'texttexttexttexttexttexttexttexttexttexttext' ) . width + "px Times" ;
}
function startDemo ( ) {
function startDemo ( ) {
demoStarted = true
demoStarted = true
octx . font = '20px Times' ;
makeGoodOutputFont ( )
octx . font = . 8 * output . width * 20 / octx . measureText ( 'texttexttexttexttexttexttexttexttexttexttext' ) . width + "px Times" ;
Tesseract . recognize ( input )
Tesseract . recognize ( input )
. progress ( progress )
. progress ( progress )
@ -54,12 +70,15 @@ function result(res){
res . words . forEach ( function ( w ) {
res . words . forEach ( function ( w ) {
var b = w . bbox ;
var b = w . bbox ;
ioctx . strokeWidth = 2
ioctx . strokeStyle = 'red'
ioctx . strokeStyle = 'red'
ioctx . strokeRect ( b . x0 , b . y0 , b . x1 - b . x0 , b . y1 - b . y0 )
ioctx . strokeRect ( b . x0 , b . y0 , b . x1 - b . x0 , b . y1 - b . y0 )
ioctx . beginPath ( )
ioctx . beginPath ( )
ioctx . moveTo ( w . baseline . x0 , w . baseline . y0 )
ioctx . moveTo ( w . baseline . x0 , w . baseline . y0 )
ioctx . lineTo ( w . baseline . x1 , w . baseline . y1 )
ioctx . lineTo ( w . baseline . x1 , w . baseline . y1 )
ioctx . strokeStyle = 'yellow '
ioctx . strokeStyle = 'green '
ioctx . stroke ( )
ioctx . stroke ( )
@ -71,4 +90,39 @@ function result(res){
document . addEventListener ( 'scroll' , startDemoIfVisible )
document . addEventListener ( 'scroll' , startDemoIfVisible )
startDemoIfVisible ( )
startDemoIfVisible ( )
function clearOverLayAndOutput ( ) {
ioctx . clearRect ( 0 , 0 , input _overlay . width , input _overlay . height )
octx . clearRect ( 0 , 0 , output . width , output . height )
}
function displayPlayButtonFor ( lang ) {
makeGoodOutputFont ( )
octx . textAlign = 'center'
octx . fillText ( 'Play' , output . width / 2 , output . height / 2 )
output . addEventListener ( 'click' , function play ( ) {
output . removeEventListener ( 'click' , play )
Tesseract . recognize ( input , lang )
. progress ( progress )
. then ( result )
} )
}
options . forEach ( function ( option ) {
option . addEventListener ( 'click' , function ( ) {
clearOverLayAndOutput ( )
options . forEach ( function ( option ) { option . className = 'option' } )
option . className = 'option selected'
if ( option . lang in lang _demo _images ) {
input . src = lang _demo _images [ option . lang ]
displayPlayButtonFor ( option . lang )
}
} )
} )