]> _ Git - 1000pourcent.git/commitdiff
wip #3207 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 9 Dec 2019 15:29:28 +0000 (16:29 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 9 Dec 2019 15:29:28 +0000 (16:29 +0100)
assets/inputsmall.jpg
js/1000pct.js
js/ocr.js
js/perspective.js

index 3300392bb55260fbefbf3ab24f82fea0c058c6e6..a4d7c70ab78e71e180fac774c34dfd9f9a0062e1 100644 (file)
Binary files a/assets/inputsmall.jpg and b/assets/inputsmall.jpg differ
index 21f33ed80c165abfb7601b442ea71fbab55f0e69..58e657af8561dddd4afff4724528d4e063bb37b3 100644 (file)
@@ -15,7 +15,6 @@ function appReady() {
 }
 
 
-
 function drawImage(url, id, callback) {
     var img = new Image();
     img.setAttribute('id', id);
@@ -98,7 +97,9 @@ function detectBoard(id, width, height, draw) {
 
     // We know that the board is delimited by two 5 sides contours. We find these two contours and select the smallest
     let boardContour;
-    if (filterByVertices.length === 2) {
+    if (filterByVertices.length === 1) {
+        boardContour = filterByVertices[0];
+    } else if (filterByVertices.length === 2) {
         // If we just have two contours, no need to go further
         boardContour = filterByVertices[1];
     } else {
@@ -145,7 +146,7 @@ function sortArea(a, b) {
 
 function drawContours(canvas, contours, type, width, height) {
     let tmp = new cv.MatVector();
-    for (let i = 0; i < contours.length; ++i) {
+    for (let i = 0; i < contours.length; i++) {
         tmp.push_back(contours[i][type]);
     }
 
index 0ebe67c9a94808b198b6b8ca041b75f3480f6c1b..231b030a15e495c9a1e983d37e183f2291d47c45 100644 (file)
--- a/js/ocr.js
+++ b/js/ocr.js
@@ -1,7 +1,7 @@
 function onTesseractReady() {
     console.log('onTesseractReady()');
 
-    let types = {malus: 'abc', bonus: 'd', 'number': 'efghijklmno'};
+    let types = {malus: 'abc', bonus: 'd', 'number': 'efghijklmnopqrstuvwxyz'};
     window.tesseract = {};
     (async () => {
         for (var type in types) {
@@ -63,7 +63,7 @@ function recognizeChars(canvas) {
 function extractRegion(src, region, color, area) {
     let drawId = 'color_' + color + '_area';
 
-    var coef = 1000 / 500;
+    var coef = 400 / 500;
     region[0] *= coef;
     region[1] *= coef;
     region[2] *= coef;
@@ -90,7 +90,7 @@ function extractRegion(src, region, color, area) {
     // Grayscale
     cv.cvtColor(res, res, cv.COLOR_RGBA2GRAY, 0);
     // Brightness
-    cv.convertScaleAbs(res, res, 3, 100);
+    cv.convertScaleAbs(res, res, 2.25, 100);
     // Contrast
     cv.equalizeHist(res, res);
 
@@ -101,29 +101,14 @@ function extractRegion(src, region, color, area) {
 }
 
 function ocr(image, color, area) {
-    let worker = new Tesseract.createWorker();
-
     (async () => {
         const {data: {text}} = await window.tesseract[area].addJob('recognize', image);
-        var t = translate(text);
-        console.log(color, area, text, t);
-        regions[color][area] = t;
+        regions[color][area] = translate(text);
         decodedRegions++;
-        if (decodedRegions == 12) {
+        if (decodedRegions === 12) {
             document.getElementById('res').innerText = JSON.stringify(regions);
         }
     })();
-    // try {
-    //     Tesseract.recognize(
-    //         image,
-    //         'eng',
-    //         {logger: m => console.log(m)}
-    //     ).then(({data: {text}}) => {
-    //         regions[color][area] = text;
-    //     })
-    // } catch (e) {
-    //
-    // }
 }
 
 var map = {
@@ -141,7 +126,19 @@ var map = {
     l: '7',
     m: '8',
     n: '9',
-    o: '?'
+    o: '?',
+    p: '0',
+    q: '1',
+    r: '2',
+    s: '3',
+    t: '4',
+    u: '5',
+    v: '6',
+    w: '7',
+    x: '8',
+    y: '9',
+    z: '?',
+
 }
 
 function translate(t) {
index 22c66cce84b4094c70011e8353c0fee6bceb8592..52b144bd7523bb03b3e2cde3de41acf727f51915 100644 (file)
@@ -14,10 +14,9 @@ function correctPerspective(contours) {
     var minIndex = distances.indexOf(min);
 
     function cindex(i) {
-        return (minIndex + 1 + i) % 5;
+        return (minIndex + 5 + 1 + i) % 5;
     }
 
-
     // Find interection of two lines to include the black corner into the board
     let c00 = contours[cindex(-2)];
     let c01 = contours[cindex(-1)];
@@ -61,7 +60,7 @@ function correctPerspective(contours) {
     cv.warpPerspective(src, finalDest, M, dsize, cv.INTER_LINEAR, cv.BORDER_CONSTANT, new cv.Scalar());
 
     // Resize the board to be a square
-    var finalSize = 1000;
+    var finalSize = 400;
     let boardSized = cv.Mat.zeros(finalSize, finalSize, cv.CV_8UC3);
     let boardSize = new cv.Size(finalSize, finalSize)
     cv.resize(finalDest, boardSized, boardSize, 0, cv.INTER_LINEAR);