}
-
function drawImage(url, id, callback) {
var img = new Image();
img.setAttribute('id', id);
// 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 {
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]);
}
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) {
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;
// 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);
}
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 = {
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) {
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)];
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);