xxxxxxxxxx
90
var ctracker = null;
let capture = null;
let capWidth = 640;
let capHeight = 480;
let isStarted = false;
function setup() {
createCanvas(capWidth, capHeight);
noLoop();
}
function draw() {
if(isStarted){
d = 10000;
let blurFactor = 10;
var positions = ctracker.getCurrentPosition();
if( positions ){
let x1 = positions[0][0];
let y1 = positions[0][1];
let x2 = positions[10][0];
let y2 = positions[10][1];
d = dist(x1,y1,x2,y2);
blurFactor = map( d, 200, 50, 0, 10 );
}
if( blurFactor < 0 ){
blurFactor = 0;
}
if( blurFactor > 10 ){
blurFactor = 10;
}
// console.log(blurFactor)
clear();
push();
translate(width, 0);
scale(-1, 1);
image(capture, 0, 0, width, height);
filter(BLUR, blurFactor);
pop();
textAlign(RIGHT);
fill(255);
let rounded = round(blurFactor, 2);
text(rounded, width-20, 20);
}else{
background('#EEEEEE');
textAlign(CENTER);
text("Click to start the camera", width/2, height/2);
}
}
function mousePressed(){
if( !isStarted ){
frameRate(10)
capture = createCapture(VIDEO);
capture.size(capWidth, capHeight);
capture.hide();
pixelDensity(1);
ctracker = new clm.tracker();
ctracker.init();
ctracker.start(capture.elt);
isStarted = true;
loop();
}
}