Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.video.*;
- Capture cam;
- PImage bg;
- boolean flg_bg = false;
- void setup(){
- size(320, 240);
- String[] cameras = Capture.list();
- for(int i=0; i<cameras.length; i++){
- println("[" + i + "] " + cameras[i]);
- }
- cam = new Capture(this, cameras[3]);
- cam.start();
- }
- void draw(){
- if(cam.available() == true){
- cam.read();
- }
- if(bg == null){
- image(cam, 0, 0);
- }
- else{
- cam.loadPixels();
- bg.loadPixels();
- for(int i=0; i<cam.pixels.length; i++){
- float y1 = 0.299 * red(cam.pixels[i]) + 0.587 * green(cam.pixels[i]) + 0.114 * blue(cam.pixels[i]);
- float y2 = 0.299 * red(bg.pixels[i]) + 0.587 * green(bg.pixels[i]) + 0.114 * blue(bg.pixels[i]);
- float d = abs(y1 - y2);
- if(d > 30){
- cam.pixels[i] = color(255, 0, 0);
- }
- }
- cam.updatePixels();
- image(cam, 0, 0);
- }
- if(flg_bg){
- bg = get(0, 0, 320, 240);
- flg_bg = false;
- }
- }
- void mousePressed(){
- flg_bg = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement