Browse Source

demo

pull/24/head
Guillermo 9 years ago
parent
commit
cb9e2d5928
  1. 2
      animation/animate.js
  2. 136
      css/main.css
  3. 148
      demo.js
  4. BIN
      img/bg.png
  5. BIN
      img/eng_bw.png
  6. 58
      index.html

2
animation/animate.js

@ -16,7 +16,7 @@ function fixdim() {
var doc = document.documentElement; var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
logo_wrap.style.top = top / 2 + 'px' // logo_wrap.style.top = top / 2 + 'px'
var rect = splash.getBoundingClientRect() var rect = splash.getBoundingClientRect()
var bottom = rect.top + rect.height var bottom = rect.top + rect.height

136
css/main.css

@ -15,7 +15,9 @@ body, html{
#splash { #splash {
overflow: hidden; overflow: hidden;
background-color: #425565; background-color: #425565;
// background: linear-gradient(90deg, #eb6b8f, #ffee75); background: url(../img/bg.png);
background-size: cover;
background-position: center;
} }
#logo-wrap { #logo-wrap {
@ -24,6 +26,10 @@ body, html{
position: relative; position: relative;
} }
#demo-instructions {
display: none;
}
#logo-canvas { #logo-canvas {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
@ -36,12 +42,13 @@ body, html{
max-width: 100%; max-width: 100%;
} }
#get-started-wrap { .get-started-wrap {
text-align: center; text-align: center;
position: relative; position: relative;
padding: 0 20px;
} }
#get-started { .get-started {
display: inline-block; display: inline-block;
color: #714d26; color: #714d26;
background: #fff; background: #fff;
@ -49,13 +56,14 @@ body, html{
font-size: 30px; font-size: 30px;
margin: 50px 0; margin: 50px 0;
border-radius: 7px; border-radius: 7px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
} }
#demo-title { #demo-title {
padding: 40px 0; padding: 40px 0;
color: #714d26; color: #714d26;
font-size: 30px; font-size: 30px;
text-align: center; // text-align: center;
} }
@ -63,23 +71,25 @@ body, html{
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
font-size: 20px; font-size: 20px;
color: #714d26; color: #3580c0;
padding: 0 15px; padding: 0 15px;
max-width: 700px; max-width: 700px;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
box-sizing: border-box;
} }
.option { .option {
padding: 10px; padding: 10px;
border-radius: 5px; border-radius: 5px;
cursor: pointer; cursor: pointer;
text-align: center;
} }
.option.selected { .option.selected {
color: #fff; color: #3580c0;
background: #5781a5; background: #d8edff;
font-weight: 400; font-weight: 400;
} }
#input { #input {
@ -87,6 +97,7 @@ body, html{
box-sizing: border-box; box-sizing: border-box;
padding: 20px; padding: 20px;
margin-top: 30px; margin-top: 30px;
border: 1px solid #ddd;
} }
#input-overlay { #input-overlay {
@ -108,10 +119,11 @@ body, html{
fill: #826f5c; fill: #826f5c;
} }
#arrow { #demo-content > #arrow {
text-align: center; text-align: center;
font-size: 30px; font-size: 30px;
color: #826f5c; color: #826f5c;
flex: 0;
} }
#arrow::before { #arrow::before {
@ -124,9 +136,26 @@ body, html{
padding: 20px; padding: 20px;
} }
#output-overlay {
white-space: pre;
font-family: Monaco, monospace;
position: absolute;
height: 100%;
width: 100%;
overflow: scroll;
border: 20px solid transparent;
box-sizing: border-box;
}
#clickme {
color: #2374b7;
text-decoration: underline;
cursor: pointer;
}
#footer { #footer {
color: #826f5c; color: #826f5c;
background-color: #ffffff; background-color: #f6f6f6;
text-align: right; text-align: right;
padding: 0 20px; padding: 0 20px;
} }
@ -144,42 +173,89 @@ body, html{
height: .7em; height: .7em;
} }
#demo-content > div {
position: relative;
flex: 1;
border: 20px solid transparent;
}
#drop-instructions-main {
display: none;
}
.commentary {
position: relative;
padding: 20px;
max-width: 700px;
margin-left: auto;
margin-right: auto;
line-height: 180%;
letter-spacing: .5 px;
}
#output-text {
margin: 0px;
width: 100%;
min-height: 200px;
box-sizing: border-box;
padding: 20px;
border: 1px solid #ddd;
}
@media (min-width: 900px) { @media (min-width: 900px) {
#drop-instructions-main {
display: block;
text-align: center;
color: #b1a79c;
}
#demo-content { #demo-content {
display: flex; display: flex;
align-items: center; align-items: center;
} }
#demo-content > div {
position: relative;
}
#input, #input-overlay { #input, #input-overlay {
margin-top: 0; margin-top: 0;
} }
#arrow::before { #arrow::before {
content: '\2192' content: '\2192';
} }
#options { #options {
margin: 40px auto; margin: 40px auto;
} }
#demo-title { // #demo-title {
width: 250px; // width: 250px;
background: #fff; // background: #fff;
margin-top: -70px; // margin-top: -70px;
position: relative; // margin-left: 40px;
padding: 20px 0; // position: relative;
} // padding: 20px 0;
// }
#demo-title::after { // #demo-title::after {
border-right: 40px solid transparent; // border-right: 40px solid transparent;
border-bottom: 70px solid white; // border-bottom: 70px solid white;
content: ' '; // content: ' ';
position: absolute; // position: absolute;
top: 0; // top: 0;
left: 100%; // left: 100%;
} // }
// #demo-title::before {
// border-left: 40px solid transparent;
// border-bottom: 70px solid white;
// content: ' ';
// position: absolute;
// top: 0;
// left: -40px;
// }
// body {
// box-sizing: border-box;
// border: 20px solid #425565;
// }
} }

148
demo.js

@ -1,72 +1,81 @@
var input = document.getElementById('input') var input = document.getElementById('input')
var input_overlay = document.getElementById('input-overlay') var input_overlay = document.getElementById('input-overlay')
var ioctx = input_overlay.getContext('2d') var ioctx = input_overlay.getContext('2d')
var output = document.getElementById('output') // var output = document.getElementById('output')
var octx = output.getContext('2d') var output_overlay = document.getElementById('output-overlay')
var output_text = document.getElementById('output-text')
var demo_instructions = document.getElementById('demo-instructions')
var drop_instructions = [].slice.call(document.querySelectorAll('.drop-instructions'))
var options = [].slice.call(document.querySelectorAll('.option'))
// 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 = { var lang_demo_images = {
eng: 'img/eng_bw.png', eng: 'img/eng_bw.png',
chi_sim: 'img/chi_sim.png', chi_sim: 'img/chi_sim.png',
rus: 'img/rus.png', rus: 'img/rus.png'
} }
function setUp(){ var lang_drop_instructions = {
output.width = input.naturalWidth eng: 'an English',
output.height = input.naturalHeight chi_sim: 'a Chinese',
rus: 'a Russian'
output.style.width = input.offsetWidth }
output.style.height = input.offsetHeight
function setUp(){
input_overlay.width = input.naturalWidth input_overlay.width = input.naturalWidth
input_overlay.height = input.naturalHeight input_overlay.height = input.naturalHeight
input_overlay.style.width = input.offsetWidth
input_overlay.style.height = input.offsetHeight
} }
setUp() setUp()
input.onload = setUp() input.onload = setUp
function isOutputVisible(){ function isOutputVisible(){
return output.getBoundingClientRect().top < dimensions.height return output_text.getBoundingClientRect().top < dimensions.height
} }
function startDemoIfVisible(argument) { 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
makeGoodOutputFont()
Tesseract.recognize(input) function start(){
.progress(progress) Tesseract.recognize(input)
.then(result) .progress(progress)
.then(result)
input.removeEventListener('load', start)
}
if(input.complete) start();
else input.addEventListener('load', start)
} }
function progress(p){ function progress(p){
var text = JSON.stringify(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.textAlign = 'center'
octx.fillText(text, output.width/2, output.height/2) // 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 result(res){ function result(res){
octx.clearRect(0, 0, output.width, output.height) // octx.clearRect(0, 0, output.width, output.height)
octx.textAlign = 'left' // octx.textAlign = 'left'
console.log('result was:',res)
output_overlay.style.display = 'none'
output_text.innerHTML = res.text
res.words.forEach(function(w){ res.words.forEach(function(w){
var b = w.bbox; var b = w.bbox;
@ -82,9 +91,9 @@ function result(res){
ioctx.stroke() ioctx.stroke()
octx.font = '20px Times'; // octx.font = '20px Times';
octx.font = 20 * (b.x1 - b.x0) / octx.measureText(w.text).width + "px Times"; // octx.font = 20 * (b.x1 - b.x0) / octx.measureText(w.text).width + "px Times";
octx.fillText(w.text, b.x0, w.baseline.y0); // octx.fillText(w.text, b.x0, w.baseline.y0);
}) })
} }
@ -95,34 +104,77 @@ startDemoIfVisible()
function clearOverLayAndOutput(){ function clearOverLayAndOutput(){
ioctx.clearRect(0,0, input_overlay.width, input_overlay.height) ioctx.clearRect(0,0, input_overlay.width, input_overlay.height)
octx.clearRect(0,0,output.width, output.height)
output_text.style.display = 'none'
demo_instructions.style.display = 'block'
// octx.clearRect(0,0,output.width, output.height)
} }
function displayPlayButtonFor(lang){ // function displayPlayButtonFor(lang){
makeGoodOutputFont() // output.addEventListener('click', function play(){
octx.textAlign = 'center' // output.removeEventListener('click', play)
octx.fillText('Play',output.width/2, output.height/2)
output.addEventListener('click', function play(){
output.removeEventListener('click', play)
Tesseract.recognize(input, lang) // Tesseract.recognize(input, lang)
.progress( progress ) // .progress( progress )
.then( result ) // .then( result )
}) // })
} // }
function play(){
demo_instructions.style.display = 'none'
output_text.style.display = 'block'
output_text.innerHTML = ''
output_overlay.innerHTML = ''
Tesseract.recognize(input, language)
.progress( progress )
.then( result )
}
options.forEach(function(option){ options.forEach(function(option){
option.addEventListener('click', function(){ option.addEventListener('click', function(){
clearOverLayAndOutput() clearOverLayAndOutput()
drop_instructions.forEach(function(di){
di.innerHTML = lang_drop_instructions[option.lang]
})
language = option.lang
options.forEach(function(option){option.className = 'option'}) options.forEach(function(option){option.className = 'option'})
option.className = 'option selected' option.className = 'option selected'
if(option.lang in lang_demo_images){ if(option.lang in lang_demo_images){
input.src = lang_demo_images[option.lang] input.src = lang_demo_images[option.lang]
displayPlayButtonFor(option.lang) // displayPlayButtonFor(option.lang)
} }
}) })
})
document.body.addEventListener('drop', function(e){
e.stopPropagation();
e.preventDefault();
var file = e.dataTransfer.files[0]
var reader = new FileReader();
Tesseract.recognize(file, language)
.progress( progress )
.then( result )
reader.onload = function(e){
input.src = e.target.result;
input.onload = function(){
setUp();
}
}
reader.readAsDataURL(file);
}) })

BIN
img/bg.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
img/eng_bw.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

58
index.html

@ -6,7 +6,7 @@
<link rel="stylesheet" type="text/css" href="css/main.css"> <link rel="stylesheet" type="text/css" href="css/main.css">
<link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
</head> </head>
<body> <body ondragover="return false">
<div id="splash"> <div id="splash">
<div id="logo-wrap" class="header"> <div id="logo-wrap" class="header">
@ -14,9 +14,9 @@
<img id="logo-img" src="img/logowhite.png"> <img id="logo-img" src="img/logowhite.png">
<div id='slogan'>Pure Javascript OCR</div> <div id='slogan'>Pure Javascript OCR</div>
</div> </div>
<div id='get-started-wrap'> <div class='get-started-wrap'>
<a href="https://github.com/naptha/tesseract.js#tesseractjs"> <a href="https://github.com/naptha/tesseract.js#tesseractjs">
<div id='get-started'> <div class='get-started'>
<svg id="github" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg> <svg id="github" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
Get Started Get Started
</div> </div>
@ -25,21 +25,47 @@
</div> </div>
<div id='demo'> <div id='demo'>
<div id='demo-title'>Demo</div> <!-- <div class="commentary">
<div id='options'> <div id='demo-title'>Demo</div>
<div class="option selected" lang='eng'>English</div> <p>Wherein we show you that Tesseract.js works, and let you try it with your own images.</p>
<div class="option" lang='chi_sim'>Chinese</div>
<div class="option" lang='rus'>Russian</div>
</div> </div>
<div id='demo-content'>
<div> -->
<canvas id='input-overlay'></canvas> <div class='commentary'>
<img id='input' src="img/eng_bw.png"/> <p><b>Tesseract.js</b> can recognize text in <b>over 60 languanges</b>, in <b><code>&lt;img></code> elements</b>, <b><code>&lt;video></code> elements</b>, <b><code>&lt;canvas></code> elements</b>, <b>remote urls</b>, <b>dropped files</b>, and more! <a href='https://github.com/naptha/tesseract.js#tesseractjs'>Example code and API docs are on GitHub</a>.</p>
</div>
<div id='demo-body'>
<div id='options'>
<div class="option selected" lang='eng'>English Demo</div>
<div class="option" lang='chi_sim'>Chinese Demo</div>
<div class="option" lang='rus'>Russian Demo</div>
</div> </div>
<div id='arrow'></div> <div id='drop-instructions-main'><p>Drop <span class='drop-instructions'>an English</span> image on this page to OCR it!</p></div>
<div> <div id='demo-content'>
<canvas id='output'></canvas> <div>
<canvas id='input-overlay'></canvas>
<img id='input' src="img/eng_bw.png"/>
</div>
<div id='arrow'></div>
<div>
<div id='output-overlay'></div>
<textarea id='output-text'></textarea>
<div id='demo-instructions'>
<span id='clickme' onclick='play()'>Click here to recognize text in the demo image</span>, or drop <span class='drop-instructions'>an English</span> image anywhere on this page.
</div>
<!-- <canvas id='output'></canvas> -->
</div>
</div> </div>
<div class='get-started-wrap'>
<br/>
<a href="https://github.com/naptha/tesseract.js#tesseractjs">
<div class='get-started'>
<svg id="github" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
Actually Get Started
</div>
</a>
</div>
</div> </div>
</div> </div>
@ -56,7 +82,7 @@
<script src="animation/hypercube.js"></script> <script src="animation/hypercube.js"></script>
<script src="animation/animate.js"></script> <script src="animation/animate.js"></script>
<script src='https://cdn.rawgit.com/naptha/tesseract.js/a01d2a2/dist/tesseract.js'></script> <script src="https://cdn.rawgit.com/naptha/tesseract.js/0.1.5/dist/tesseract.js"></script>
<script src="demo.js"></script> <script src="demo.js"></script>
</body> </body>
</html> </html>
Loading…
Cancel
Save