-
Notifications
You must be signed in to change notification settings - Fork 6
/
recognizer.html
89 lines (81 loc) · 3.13 KB
/
recognizer.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!doctype html>
<html>
<script src="/build/penguin-recognizer.js"></script>
<script>
function load_stage_index(resolve, reject) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "/resources/json/stage_index.json", true);
xmlhttp.onload = function () {
stage_index = xmlhttp.responseText;
Module.load_stage_index(stage_index);
console.log("[OK] loaded stage_index");
resolve();
};
xmlhttp.send();
};
function load_hash_index(resolve, reject) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "/resources/json/hash_index.json", true);
xmlhttp.onload = function () {
hash_index = xmlhttp.responseText;
Module.load_hash_index(hash_index);
console.log("[OK] loaded hash_index");
resolve();
};
xmlhttp.send();
};
function load_templs(resolve, reject) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "/resources/icon/items", true);
xmlhttp.responseType = "document";
xmlhttp.onload = function () {
var lst = xmlhttp.response.getElementsByTagName('li');
new Promise((resolve, reject) => {
[...lst].map(el => el.innerText).forEach((fn, index, arr) => {
const xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", `/resources/icon/items/${fn}`, true);
xmlhttp.responseType = "arraybuffer";
xmlhttp.onload = function () {
Module.load_templs(fn.split('.')[0], xmlhttp.response);
console.log(`[OK] loaded templ: ${fn}`);
if (index === arr.length - 1) {
resolve();
}
};
xmlhttp.send();
});
}).then(() => { resolve(); })
};
xmlhttp.send();
};
function recognize() {
recognizer = new Module.Recognizer("RESULT");
const xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", `/test_images/new.png`, true);
xmlhttp.responseType = "arraybuffer";
xmlhttp.onload = function () {
// recognize(JSArrayBuffer img, bool detail, bool pretty_print)
try { report = recognizer.recognize(xmlhttp.response, true, true); }
catch (e) {
console.error(Module.getExceptionMessage(e));
}
finally {
console.log(report);
}
};
xmlhttp.send();
}
Module.onRuntimeInitialized = _ => {
console.log(`version: ${Module.version}`);
console.log(`opencv_version: ${Module.opencv_version}`);
Module.load_server("CN");
const promise1 = new Promise(load_stage_index);
const promise2 = new Promise(load_hash_index);
const promise3 = new Promise(load_templs);
Promise.all([promise1, promise2, promise3]).then(() => {
console.log(`env check: ${Module.env_check()}`);
recognize();
});
};
</script>
</html>