Motion

import processing.video.*; import processing.sound.*; SoundFile file; Capture cam; Capture cam2; int count=1; PImage myImg=null; PImage myImg2=null; void setup() { frameRate(1); file = new SoundFile(this, "/Users/HuanD18/Documents/Processing/cenahorn.mp3"); file.play(); size(600, 300); cam = new Capture(this, 320, 240, 30); cam.start(); cam2 = new Capture(this, 320, 240, 30); cam2.start(); } void draw() { if(count<2){ if(cam.available()) { cam.read(); myImg=cam; count++; } }else{ if(cam2.available()) { cam2.read(); myImg2=cam2; } } if(myImg!=null && myImg2!=null){ image(myImg, 0, 0,200,200); image(myImg2, 300, 0,200,200); loadPixels(); myImg.loadPixels(); myImg2.loadPixels(); int change = 0; int threshold = 180; for (int i = 0; i < 200 && count>1; i++) { float r = red(myImg.pixels[i]); float r2 = red(myImg2.pixels[i]); if(r!=r2){ change++; } } if(change>threshold){ System.out.println("Intruder Alert!!!"); myImg = null; myImg2 = null; count = 0; } updatePixels(); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.