Some more helper functions

This commit is contained in:
Ruben van de Ven 2020-09-22 09:11:45 +02:00
parent 377c60ac92
commit 058a656d13

View file

@ -219,20 +219,20 @@ function drawPart(feature, closed) {
} }
/** // /**
* Wrapper around p5.js color class // * Wrapper around p5.js color class
* @param {*} c color, either as array, or string (css name or HEX string) // * @param {*} c color, either as array, or string (css name or HEX string)
*/ // */
function getColor(c) { // function getColor(c) {
if(!Array.isArray(c)) c = [c]; // if(!Array.isArray(c)) c = [c];
return new p5.Color(p5.instance, c); // return new p5.Color(p5.instance, c);
} // }
var colors = { // var colors = {
red: getColor('red'), // red: getColor('red'),
blue: getColor('blue'), // blue: getColor('blue'),
green: getColor('green'), // green: getColor('green'),
}; // };
function faceDistance(face1, face2){ function faceDistance(face1, face2){
// distance between faces, in pixels, not meters.. for now // 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; 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(){ function getBoundingBox(){
// arguments contains points, or sets of points. Find bbox // arguments contains points, or sets of points. Find bbox
console.log(arguments)
// return { const points = mergePoints(...arguments);
// top:
// left: const xs = points.map((point) => point.x);
// width: const ys = points.map((point) => point.y);
// height:
// } 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) { function parseDetectionResults(results) {
@ -277,6 +300,7 @@ function parseDetectionResults(results) {
const landmarks = result.landmarks._positions.map((pos) => parseCoordinate(pos)); const landmarks = result.landmarks._positions.map((pos) => parseCoordinate(pos));
let detection = { let detection = {
'landmarks': landmarks, 'landmarks': landmarks,
// TODO: rotation
'parts': {}, 'parts': {},
'box': { 'box': {
x: result.alignedRect._box._x * factor_x, x: result.alignedRect._box._x * factor_x,
@ -292,9 +316,6 @@ function parseDetectionResults(results) {
} }
return detections; return detections;
// result.parts
// result.alignedRect._box
// factor_x, factor_y
} }
/** /**