Browse Source

Upgrade to tesseract.js@2.0.0-beta.1

pull/389/head
Jerome Wu 5 years ago
parent
commit
9863bd8f74
  1. 34
      demo.js
  2. 2
      index.html

34
demo.js

@ -25,7 +25,9 @@ var lang_drop_instructions = {
rus: 'a Russian' rus: 'a Russian'
} }
var tessWorker = new Tesseract.TesseractWorker(); var worker = new Tesseract.createWorker({
logger: progressUpdate,
});
function setUp(){ function setUp(){
input_overlay.width = input.naturalWidth input_overlay.width = input.naturalWidth
@ -49,10 +51,12 @@ function startDemoIfVisible(argument) {
function startDemo(){ function startDemo(){
demoStarted = true demoStarted = true
function start(){ async function start(){
tessWorker.recognize(input) await worker.load();
.progress(progressUpdate) await worker.loadLanguage('eng');
.then(result) await worker.initialize('eng');
const { data } = await worker.recognize(input);
result(data);
input.removeEventListener('load', start) input.removeEventListener('load', start)
} }
@ -167,16 +171,18 @@ function clearOverLayAndOutput(){
// } // }
function play(){ async function play(){
demo_instructions.style.display = 'none' demo_instructions.style.display = 'none'
output_text.style.display = 'block' output_text.style.display = 'block'
output_text.innerHTML = '' output_text.innerHTML = ''
// output_overlay.innerHTML = '' // output_overlay.innerHTML = ''
tessWorker.recognize(input, language) await worker.load();
.progress( progressUpdate ) await worker.loadLanguage(language);
.then( result ) await worker.initialize(language);
const { data } = await worker.recognize(input);
result(data);
} }
options.forEach(function(option){ options.forEach(function(option){
@ -201,15 +207,17 @@ options.forEach(function(option){
}) })
document.body.addEventListener('drop', function(e){ document.body.addEventListener('drop', async function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
var file = e.dataTransfer.files[0] var file = e.dataTransfer.files[0]
var reader = new FileReader(); var reader = new FileReader();
await worker.load();
await worker.loadLanguage(language);
await worker.initialize(language);
const { data } = await worker.recognize(file);
result(data);
tessWorker.recognize(file, language)
.progress( progressUpdate )
.then( result )
reader.onload = function(e){ reader.onload = function(e){
input.src = e.target.result; input.src = e.target.result;

2
index.html

@ -92,7 +92,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://unpkg.com/tesseract.js@2.0.0-alpha.11/dist/tesseract.min.js"></script> <script src="https://unpkg.com/tesseract.js@2.0.0-beta.1/dist/tesseract.min.js"></script>
<script src="demo.js"></script> <script src="demo.js"></script>
<script> <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

Loading…
Cancel
Save