xxxxxxxxxx
// computer vision test
// hipster burglar alarm
var capture, imageout;
var sound;
var playing = 0;
function preload() {
sound = loadSound("2.mp3");
}
function setup() {
createCanvas(windowWidth, windowHeight);
capture = createCapture(VIDEO); // this opens up the camera
pixelDensity(1); // turns off oversampling ("retina display")
capture.size(32, 32); // this is in pixels
capture.hide(); // telling the browser to hide the camera so we can draw it ourselves
imageout = createImage(32, 32); // create an empty picture
}
function draw() {
background(0);
capture.loadPixels();
noSmooth();
var s = 0;
for(let i = 0;i<capture.pixels.length;i+=4)
{
s+=capture.pixels[i+1] // GREEN
}
s/=(capture.pixels.length/4);
s/=255.;
if(s<0.5) {
if(playing==0) {
sound.play();
playing = 1;
}
}
else {
playing = 0;
}
image(capture, 0, 0, width, height);
textSize(80);
text(s, width/2, height/2);
}