From 058a656d13530cb1886dada4ef9a3ea3d3251e4a Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Tue, 22 Sep 2020 09:11:45 +0200 Subject: [PATCH] Some more helper functions --- dist/static/assets/webcam.js | 67 +++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/dist/static/assets/webcam.js b/dist/static/assets/webcam.js index b679c30b..9dfcec94 100644 --- a/dist/static/assets/webcam.js +++ b/dist/static/assets/webcam.js @@ -219,20 +219,20 @@ function drawPart(feature, closed) { } -/** - * Wrapper around p5.js color class - * @param {*} c color, either as array, or string (css name or HEX string) - */ -function getColor(c) { - if(!Array.isArray(c)) c = [c]; - return new p5.Color(p5.instance, c); -} +// /** +// * Wrapper around p5.js color class +// * @param {*} c color, either as array, or string (css name or HEX string) +// */ +// function getColor(c) { +// if(!Array.isArray(c)) c = [c]; +// return new p5.Color(p5.instance, c); +// } -var colors = { - red: getColor('red'), - blue: getColor('blue'), - green: getColor('green'), -}; +// var colors = { +// red: getColor('red'), +// blue: getColor('blue'), +// green: getColor('green'), +// }; function faceDistance(face1, face2){ // distance between faces, in pixels, not meters.. for now @@ -259,16 +259,39 @@ function faceDistance(face1, face2){ return Math.sqrt( Math.pow(dx, 2) + Math.pow(dy, 2) ) - r1 - r2; } +function mergePoints() { + // a points should be {x: , y: } + + // collect all points in the arguments: + let points = []; + + for(let arg of arguments) { + if(Array.isArray(arg)) { + points.push(...arg); + } else { + points.push(arg); + } + } + return points; +} + function getBoundingBox(){ // arguments contains points, or sets of points. Find bbox - console.log(arguments) - // return { - // top: - // left: - // width: - // height: - // } + const points = mergePoints(...arguments); + + const xs = points.map((point) => point.x); + const ys = points.map((point) => point.y); + + const minx = Math.min(...xs); + const miny = Math.min(...ys); + + return { + x: minx, + y: miny, + width: Math.max(...xs) - minx, + height: Math.max(...ys) - miny, + } } function parseDetectionResults(results) { @@ -277,6 +300,7 @@ function parseDetectionResults(results) { const landmarks = result.landmarks._positions.map((pos) => parseCoordinate(pos)); let detection = { 'landmarks': landmarks, + // TODO: rotation 'parts': {}, 'box': { x: result.alignedRect._box._x * factor_x, @@ -292,9 +316,6 @@ function parseDetectionResults(results) { } return detections; - // result.parts - // result.alignedRect._box - // factor_x, factor_y } /**