-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
72 lines (66 loc) · 2.1 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="theme-color" content="#2B3A42" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Handwriting</title>
<link rel="stylesheet" href="css/style.css">
<script src="dist/mlhand.js"></script>
<script>
function onResult(results) {
let candidates = document.getElementsByClassName('candidates')[0]
if (results && results.length) {
candidates.innerHTML = ''
document.getElementById('result').value += results[0].pattern;
console.log("Match: " + JSON.stringify(results[0]))
for (let i = 1; i < results.length; i++) {
let button = document.createElement('button')
button.innerText = results[i].pattern;
button.title = results[i].score;
candidates.appendChild(button);
}
} else {
candidates.innerHTML = 'No match'
}
}
function initPad() {
let canvas = document.getElementsByClassName('pad')[0]
canvas.width = document.body.clientWidth
canvas.height = document.body.clientHeight * 0.4;
document.getElementById('result').value = '';
const hw = new Mlhand({
canvas: canvas,
threshold: 0.85,
onResult: onResult,
debug: true
});
document.getElementsByClassName('space')[0].onclick = ()=>{
document.getElementById('result').value = document.getElementById('result').value + ' ';
},
document.getElementsByClassName('backspace')[0].onclick = ()=>{
document.getElementById('result').value = document.getElementById('result').value.slice(0, -1);
}
document.getElementsByClassName('back')[0].onclick = ()=>{
hw.previous();
}
}
window.addEventListener('load', initPad);
</script>
</head>
<body>
<nav>
<h1>Malayalam Handwriting recognition</h1>
</nav>
<textarea id="result"></textarea>
<div class="candidates"></div>
<div class="container">
<canvas class="pad"></canvas>
<div class="tools">
<button class='back'>Back ↶</button>
<button class='space'>Space</button>
<button class='backspace'>Backspace ⇦</button>
</div>
</div>
</body>
</html>