]> _ Git - 1000pourcent.git/commitdiff
wip #3207 @6
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 2 Jan 2020 15:11:33 +0000 (16:11 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 2 Jan 2020 15:11:33 +0000 (16:11 +0100)
index.html
js/1000pct.js
js/ocr.js
js/perspective.js
manifest.webmanifest.json
style.less

index 04df4997c67cf02a4a45ed69a019a79d5ec693c8..1a2bc45d79db378ff4d1fc1753db2f368ea691a4 100644 (file)
@@ -4,7 +4,7 @@
     <meta charset="UTF-8">
     <title>1000% Prototype</title>
     <link href="style.css" rel="stylesheet" type="text/css">
-    <meta name="theme-color" content="#0c6638">
+    <meta name="theme-color" content="#00632e">
     <link rel="manifest" href="https://demo1.cubedesigners.com/1000pct/manifest.webmanifest.json">
 </head>
 <body>
index 7ca77fedcf472b618a37104d63ec7b7ba09ffad3..a3830086b1a96fa38596c22ebd715ef9d8fddc57 100644 (file)
@@ -7,7 +7,7 @@ function appReady() {
         navigator.mediaDevices.getUserMedia({
             video: {
                 width: {min: 1280},
-                height: {min: 720},
+                height: {min: 1280},
                 facingMode: {exact: "environment"}
             }, audio: false
         }).then(function (stream) {
@@ -31,7 +31,6 @@ function recognizeAttempt() {
     input.getContext('2d').drawImage(video, 0, 0, input.width, input.height);
     var start = Date.now();
     var contour = detectBoard('input', input.width, input.height, true);
-    cleanOpencvReferences();
     if (contour !== false) {
         console.log(Date.now() - start);
         correctPerspective(contour);
index 6f200d485caa400f7813484ab9711514829a5406..83541c1442f07bd25c6b549a8d9eae6520fd6b60 100644 (file)
--- a/js/ocr.js
+++ b/js/ocr.js
@@ -1,7 +1,11 @@
 function onTesseractReady() {
     console.log('onTesseractReady()');
 
-    let types = {malus: 'abc', bonus: 'd', 'number': 'efghijklmnopqrstuvwxyz'};
+    let types = {
+        malus: {chars: 'abc', seg: '10'},
+        bonus: {chars: 'd', seg: '10'},
+        number: {chars: 'efghijklmnopqrstuvwxyz', seg: '7'}
+    };
     window.tesseract = {};
     (async () => {
         for (var type in types) {
@@ -15,7 +19,9 @@ function onTesseractReady() {
                 await worker.loadLanguage('font');
                 await worker.initialize('font');
                 await worker.setParameters({
-                    tessedit_char_whitelist: types[type],
+                    tessedit_char_whitelist: types[type].chars,
+                    tessedit_pageseg_mode: types[type].seg,
+                    tessjs_create_box: '1',
                 });
                 window.tesseract[type].addWorker(worker);
             }
@@ -26,6 +32,7 @@ function onTesseractReady() {
 
 function recognizeChars(canvas) {
     let src = cv.imread(canvas);
+    opencvReferences.push(src);
     var areas = {
         'blue': {
             'bonus': [333, 588, 40, 53, 0],
@@ -61,9 +68,11 @@ function recognizeChars(canvas) {
 
 
 function extractRegion(src, region, color, area) {
+    console.log('Extract region');
+
     let drawId = 'color_' + color + '_' + area;
 
-    var coef = 500 / 500;
+    var coef = 1000 / 500;
     region[0] *= coef;
     region[1] *= coef;
     region[2] *= coef;
@@ -71,9 +80,11 @@ function extractRegion(src, region, color, area) {
 
     let rect = new cv.Rect(region[0], region[1], region[2], region[3]);
     let dst = src.roi(rect);
+    opencvReferences.push(dst);
 
     let res = new cv.Mat();
-    let w, h;
+    opencvReferences.push(res);
+    let w, h, h2;
     w = region[2];
     h = region[3];
 
@@ -89,8 +100,12 @@ function extractRegion(src, region, color, area) {
     cv.bitwise_not(res, res);
     // Grayscale
     cv.cvtColor(res, res, cv.COLOR_RGBA2GRAY, 0);
+
+    var brightness = 2;
+    h2 = 30 * coef;
+
     // Brightness
-    cv.convertScaleAbs(res, res, 2.25, 100);
+    cv.convertScaleAbs(res, res, brightness, 100);
     // Contrast
     cv.equalizeHist(res, res);
 
@@ -102,11 +117,13 @@ function extractRegion(src, region, color, area) {
 
 function ocr(image, color, area) {
     (async () => {
-        const {data: {text}} = await window.tesseract[area].addJob('recognize', image);
-        regions[color][area] = translate(text);
+        const res = await window.tesseract[area].addJob('recognize', image);
+        regions[color][area] = translate();
         decodedRegions++;
         if (decodedRegions === 12) {
             document.getElementById('res').innerText = JSON.stringify(regions);
+            window.navigator.vibrate([100, 100, 200]);
+            cleanOpencvReferences();
         }
     })();
 }
index 0f739aa8de2f43e63aa55eb9b733c081610610e1..a7dcce343beda1caa9342a03c3602426393e5ec6 100644 (file)
@@ -60,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 = 500;
+    var finalSize =1000;
     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);
index a596ad6b4d6b2abb74212551b9173c7cb9fdc422..4f0e879aba676ffd7f3383afdfda2611e5561d81 100644 (file)
@@ -4,8 +4,8 @@
   "description": "",
   "display": "standalone",
   "orientation": "any",
-  "background_color": "#0c6638",
-  "theme_color": "#0c6638",
+  "background_color": "#00632e",
+  "theme_color": "#00632e",
   "start_url": "https://demo1.cubedesigners.com/1000pct/",
   "scope": "https://demo1.cubedesigners.com/1000pct/",
   "icons": [
index e83d1c166bdecab39d116094c5cebe0f631a0a91..ce747f712c140004b74c47449a2b4c7005d99bde 100644 (file)
@@ -4,7 +4,7 @@
 }
 
 body{
-  background-color:#0c6638;
+  background-color:#00632e;
 }
 
 #input{