]> _ Git - 1000pourcent.git/commitdiff
wip #3222 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Nov 2019 17:54:56 +0000 (18:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Nov 2019 17:54:56 +0000 (18:54 +0100)
_doc/final.ttf [new file with mode: 0644]
assets/font.traineddata [deleted file]
assets/font.traineddata.gz
assets/inputsmall.jpg
index.html
js/ocr.js

diff --git a/_doc/final.ttf b/_doc/final.ttf
new file mode 100644 (file)
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 (file)
index 2ef9bf7..0000000
Binary files a/assets/font.traineddata and /dev/null differ
index bbdefb1f6a4e99bd17da9c6d534a9476187ef31c..8cc10eddfb6e01d5fdc403e28dccc5e0ea840fb7 100644 (file)
Binary files a/assets/font.traineddata.gz and b/assets/font.traineddata.gz differ
index 92499576fde36b64c99b045ff09a9e059f9483a6..3300392bb55260fbefbf3ab24f82fea0c058c6e6 100644 (file)
Binary files a/assets/inputsmall.jpg and b/assets/inputsmall.jpg differ
index 48b4f422e10e10799ab5abd47015f4d43b6ab118..bcd0c87873e2eda3388ba4e69db68472c84ba02a 100644 (file)
@@ -6,8 +6,10 @@
     <link href="style.css" rel="stylesheet" type="text/css">
 </head>
 <body>
+<pre id="res"></pre>
 <script async src="js/opencv.js" type="text/javascript"></script>
-<script async src='https://unpkg.com/tesseract.js@v2.0.0-beta.1/dist/tesseract.min.js' onload="onTesseractReady();"></script>
+<script async src='https://unpkg.com/tesseract.js@v2.0.0-beta.1/dist/tesseract.min.js'
+        onload="onTesseractReady();"></script>
 <script src="js/1000pct.js"></script>
 <script src="js/perspective.js"></script>
 <script src="js/ocr.js"></script>
index f29e7893540270f79d780f2c685c33b314c57ea3..0ebe67c9a94808b198b6b8ca041b75f3480f6c1b 100644 (file)
--- 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