Created
July 7, 2014 11:14
-
-
Save ktnyt/ec75b8747038ed8142a8 to your computer and use it in GitHub Desktop.
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); | |
for(int i = 0; i < 640; i++) { | |
for(int j = 0; j < 480; j++) { | |
color pixel = camera.pixels[i + j * 640]; | |
float R = red(pixel); | |
float G = green(pixel); | |
float B = blue(pixel); | |
if(R >= G && R >= B) { | |
// Red | |
pixel = color(R, 0, 0); | |
} else if (G >= R && G >= B) { | |
// Green | |
pixel = color(0, G, 0); | |
} else { | |
// Blue | |
pixel = color(0, 0, B); | |
} | |
picture.pixels[i + j * 640] = pixel; | |
} | |
} | |
} else { | |
picture = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment