From: Vincent Vanwaelscappel Date: Thu, 2 Jan 2020 15:11:33 +0000 (+0100) Subject: wip #3207 @6 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4b46e84d0b12440bbdb8acb062e788f86d429576;p=1000pourcent.git wip #3207 @6 --- diff --git a/index.html b/index.html index 04df499..1a2bc45 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ 1000% Prototype - + diff --git a/js/1000pct.js b/js/1000pct.js index 7ca77fe..a383008 100644 --- a/js/1000pct.js +++ b/js/1000pct.js @@ -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); diff --git a/js/ocr.js b/js/ocr.js index 6f200d4..83541c1 100644 --- 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(); } })(); } diff --git a/js/perspective.js b/js/perspective.js index 0f739aa..a7dcce3 100644 --- a/js/perspective.js +++ b/js/perspective.js @@ -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); diff --git a/manifest.webmanifest.json b/manifest.webmanifest.json index a596ad6..4f0e879 100644 --- a/manifest.webmanifest.json +++ b/manifest.webmanifest.json @@ -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": [ diff --git a/style.less b/style.less index e83d1c1..ce747f7 100644 --- a/style.less +++ b/style.less @@ -4,7 +4,7 @@ } body{ - background-color:#0c6638; + background-color:#00632e; } #input{