Last active
December 24, 2015 02:09
-
-
Save kylemcdonald/6728319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gab.opencv.*; | |
| import processing.video.*; | |
| Capture video; | |
| OpenCV bg; | |
| OpenCV opencv; | |
| PImage curBg; | |
| PImage colorDiff; | |
| float brightness = 0; | |
| void setup() { | |
| size(640, 480); | |
| video = new Capture(this, width, height); | |
| video.start(); | |
| bg = new OpenCV(this, width, height); | |
| opencv = new OpenCV(this, width, height); | |
| curBg = bg.getSnapshot(); | |
| updateDiff(); | |
| } | |
| void updateDiff() { | |
| opencv.loadImage(video); | |
| opencv.diff(curBg); | |
| colorDiff = opencv.getSnapshot(); | |
| } | |
| void draw() { | |
| pushMatrix(); | |
| scale(0.5); | |
| image(colorDiff, 0, 0); | |
| image(curBg, width, 0); | |
| popMatrix(); | |
| rect(0, 0, brightness, 10); | |
| } | |
| void keyPressed() { | |
| if(key == ' ') { | |
| bg.loadImage(video); | |
| curBg = bg.getSnapshot(); | |
| } | |
| } | |
| void captureEvent(Capture c) { | |
| key = ' '; | |
| keyPressed(); | |
| c.read(); | |
| updateDiff(); | |
| brightness = 0; | |
| colorDiff.loadPixels(); | |
| for(int y = 0; y < height; y++) { | |
| for(int x = 0; x < width; x++) { | |
| brightness += brightness(colorDiff.get(x, y)); | |
| } | |
| } | |
| brightness /= (width * height); | |
| println(brightness); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment