From: Vincent Vanwaelscappel Date: Thu, 28 Nov 2019 17:54:56 +0000 (+0100) Subject: wip #3222 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2d806b40608eb4beed28635e007c931083f139a7;p=1000pourcent.git wip #3222 @1 --- diff --git a/_doc/final.ttf b/_doc/final.ttf new file mode 100644 index 0000000..fd82831 Binary files /dev/null and b/_doc/final.ttf differ diff --git a/assets/font.traineddata b/assets/font.traineddata deleted file mode 100644 index 2ef9bf7..0000000 Binary files a/assets/font.traineddata and /dev/null differ diff --git a/assets/font.traineddata.gz b/assets/font.traineddata.gz index bbdefb1..8cc10ed 100644 Binary files a/assets/font.traineddata.gz and b/assets/font.traineddata.gz differ diff --git a/assets/inputsmall.jpg b/assets/inputsmall.jpg index 9249957..3300392 100644 Binary files a/assets/inputsmall.jpg and b/assets/inputsmall.jpg differ diff --git a/index.html b/index.html index 48b4f42..bcd0c87 100644 --- a/index.html +++ b/index.html @@ -6,8 +6,10 @@ +

 
-
+
 
 
 
diff --git a/js/ocr.js b/js/ocr.js
index f29e789..0ebe67c 100644
--- a/js/ocr.js
+++ b/js/ocr.js
@@ -1,16 +1,24 @@
 function onTesseractReady() {
     console.log('onTesseractReady()');
 
+    let types = {malus: 'abc', bonus: 'd', 'number': 'efghijklmno'};
+    window.tesseract = {};
     (async () => {
-        window.tesseractScheduler = Tesseract.createScheduler();
-        for (let i = 0; i < 4; i++) {
-            let worker = Tesseract.createWorker({
-                langPath:'./assets/',
-            });
-            await worker.load();
-            await worker.loadLanguage('font');
-            await worker.initialize('font');
-            tesseractScheduler.addWorker(worker);
+        for (var type in types) {
+
+            window.tesseract[type] = Tesseract.createScheduler();
+            for (let i = 0; i < 2; i++) {
+                let worker = Tesseract.createWorker({
+                    langPath: './assets/',
+                });
+                await worker.load();
+                await worker.loadLanguage('font');
+                await worker.initialize('font');
+                await worker.setParameters({
+                    tessedit_char_whitelist: types[type],
+                });
+                window.tesseract[type].addWorker(worker);
+            }
         }
         appReady();
     })();
@@ -42,6 +50,7 @@ function recognizeChars(canvas) {
     }
 
     window.regions = {};
+    window.decodedRegions = 0;
     for (let color in areas) {
         regions[color] = {};
         for (let area in areas[color]) {
@@ -81,7 +90,7 @@ function extractRegion(src, region, color, area) {
     // Grayscale
     cv.cvtColor(res, res, cv.COLOR_RGBA2GRAY, 0);
     // Brightness
-    cv.convertScaleAbs(res, res, 1.9, 100);
+    cv.convertScaleAbs(res, res, 3, 100);
     // Contrast
     cv.equalizeHist(res, res);
 
@@ -95,9 +104,14 @@ function ocr(image, color, area) {
     let worker = new Tesseract.createWorker();
 
     (async () => {
-        const {data: {text}} = await window.tesseractScheduler.addJob('recognize', image);
-        console.log(color, area, text);
-        regions[color][area] = text;
+        const {data: {text}} = await window.tesseract[area].addJob('recognize', image);
+        var t = translate(text);
+        console.log(color, area, text, t);
+        regions[color][area] = t;
+        decodedRegions++;
+        if (decodedRegions == 12) {
+            document.getElementById('res').innerText = JSON.stringify(regions);
+        }
     })();
     // try {
     //     Tesseract.recognize(
@@ -110,4 +124,33 @@ function ocr(image, color, area) {
     // } catch (e) {
     //
     // }
+}
+
+var map = {
+    a: 'block',
+    b: 'bomb',
+    c: 'bug',
+    d: 'rocket',
+    e: '0',
+    f: '1',
+    g: '2',
+    h: '3',
+    i: '4',
+    j: '5',
+    k: '6',
+    l: '7',
+    m: '8',
+    n: '9',
+    o: '?'
+}
+
+function translate(t) {
+    var res = '';
+    for (let i = 0; i < t.length; i++) {
+        let m = map[t[i]];
+        if (m !== undefined) {
+            res += map[t[i]];
+        }
+    }
+    return res;
 }
\ No newline at end of file