xxxxxxxxxx
var capture;
function setup() {
createCanvas(windowWidth, windowHeight);
capture = createCapture(VIDEO); // this opens up the camera
pixelDensity(1); // turns off oversampling ("retina display")
capture.size(640, 480); // this is in pixels
capture.hide(); // telling the browser to hide the camera so we can draw it ourselves
}
function draw() {
background(0);
capture.loadPixels();
for(let i = 0;i<capture.pixels.length;i+=4)
{
let L = (capture.pixels[i] + capture.pixels[i+1] + capture.pixels[i+2]) / 3;
capture.pixels[i] = L;
capture.pixels[i+1] = L;
capture.pixels[i+2] = L;
}
capture.updatePixels();
image(capture, 0, 0, width, height);
}