Last active
August 29, 2015 14:03
-
-
Save ktnyt/e7f8d0800a1d838d3342 to your computer and use it in GitHub Desktop.
Global RGB condition
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 processing.video.*; | |
| Capture camera; | |
| PImage picture = null; | |
| void setup() { | |
| size(640, 480); | |
| camera = new Capture(this, 640, 480, 30); | |
| camera.start(); | |
| } | |
| void draw() { | |
| if(camera.available() == true) { | |
| camera.read(); | |
| } | |
| if(picture == null) { | |
| set(0, 0, camera); | |
| } else { | |
| set(0, 0, picture); | |
| } | |
| } | |
| void keyPressed() { | |
| if(key == ENTER) { | |
| if(picture == null) { | |
| picture = new PImage(640, 480); | |
| float R = 0, G = 0, B = 0; | |
| for(int i = 0; i < 640; i++) { | |
| for(int j = 0; j < 480; j++) { | |
| color pixel = camera.pixels[i + j * 640]; | |
| R += red(pixel); | |
| G += green(pixel); | |
| B += blue(pixel); | |
| picture.pixels[i + j * 640] = pixel; | |
| } | |
| } | |
| if(R >= G && R >= B) { | |
| // Red | |
| picture = loadImage("Red Image"); | |
| } else if (G >= R && G >= B) { | |
| // Green | |
| picture = loadImage("Green Image"); | |
| } else { | |
| // Blue | |
| picture = loadImage("Blue Image"); | |
| } | |
| } else { | |
| picture = null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment