// Run this program only in the Java mode inside the IDE, // not on Processing.js (web mode)!! import processing.video.*; Capture cam; void setup() { size(640, 480); // check cameras String[] cameras = Capture.list(); if (cameras.length == 0) { println("There are no cameras available for capture."); exit(); } else { println("Available cameras:"); for (int i = 0; i < cameras.length; i++) { println(i+". "+cameras[i]); } } //cam = new Capture(this, cameras[0]); //Another method cam = new Capture(this, 640, 480, 30); cam.start(); } void draw() { if(cam.available()) { cam.read(); cam.loadPixels(); int total = cam.width*cam.height; int R,G,B; for (int i=0;i>16)&0xff; G=(cam.pixels[i]>>8)&0xff; B=(cam.pixels[i])&0xff; R=(R+G+B)/3; cam.pixels[i]=(R<<16)|(R<<8)|(R); } cam.updatePixels(); image(cam, 0, 0); } }