-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathbasic-scheduler.html
47 lines (40 loc) · 1.43 KB
/
basic-scheduler.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE HTML>
<html>
<head>
<script src="/dist/tesseract.min.js"></script>
</head>
<body>
<input type="file" id="uploader" multiple>
<script type="module">
// This example builds on "basic-efficient.html".
// Rather than using a single worker, a scheduler manages a pool of multiple workers.
// While performance is similar for a single file, this parallel processing results in significantly
// faster speeds when used with multiple files.
const scheduler = Tesseract.createScheduler();
// Creates worker and adds to scheduler
const workerGen = async () => {
const worker = await Tesseract.createWorker("eng", 1, {
corePath: '../../node_modules/tesseract.js-core',
workerPath: "/dist/worker.min.js",
logger: function(m){console.log(m);}
});
scheduler.addWorker(worker);
}
const workerN = 4;
(async () => {
const resArr = Array(workerN);
for (let i=0; i<workerN; i++) {
resArr[i] = await workerGen();
}
})();
const recognize = async function(evt){
const files = evt.target.files;
for (let i=0; i<files.length; i++) {
scheduler.addJob('recognize', files[i]).then((x) => console.log(x.data.text))
}
}
const elm = document.getElementById('uploader');
elm.addEventListener('change', recognize);
</script>
</body>
</html>