From: Vincent Vanwaelscappel Date: Mon, 9 Dec 2019 15:29:28 +0000 (+0100) Subject: wip #3207 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=02ad713df3b83d45e5a3dc79a116a47eb1493802;p=1000pourcent.git wip #3207 @2 --- diff --git a/assets/inputsmall.jpg b/assets/inputsmall.jpg index 3300392..a4d7c70 100644 Binary files a/assets/inputsmall.jpg and b/assets/inputsmall.jpg differ diff --git a/js/1000pct.js b/js/1000pct.js index 21f33ed..58e657a 100644 --- a/js/1000pct.js +++ b/js/1000pct.js @@ -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]); } diff --git a/js/ocr.js b/js/ocr.js index 0ebe67c..231b030 100644 --- 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) { diff --git a/js/perspective.js b/js/perspective.js index 22c66cc..52b144b 100644 --- a/js/perspective.js +++ b/js/perspective.js @@ -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);