Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.video.*;
- Capture cam;
- PImage img;
- boolean outputOne = true;
- boolean captured = false;
- boolean saved = false;
- boolean update = true;
- color cTrans = color(0, 0, 0,0);
- void setup() {
- size(640, 480);
- String[] cameras = Capture.list();
- if (cameras.length == 0) {
- println("There are no cameras available for capture.");
- exit();
- } else {
- println("Available cameras:");
- for (int i = 0; i < cameras.length; i++) {
- print(i);
- print(" , ");
- println(cameras[i]);
- }
- // The camera can be initialized directly using an
- // element from the array returned by list():
- cam = new Capture(this, cameras[49 ]);
- cam.start();
- }
- }
- void draw() {
- if (captured == false) {
- if (cam.available() == true) {
- cam.read();
- }
- image(cam, 0, 0);
- // The following does the same, and is faster when just drawing the image
- // without any additional resizing, transformations, or tint.
- //set(0, 0, cam);
- }
- else
- {
- PImage primg;
- primg = img;
- primg.loadPixels();
- for (int y = 0; y < primg.height; y++) {
- for (int x = 0; x < primg.width; x++) {
- int loc = x + y*primg.width;
- color c = primg.pixels[loc];
- float r = red(c);
- float g = green(c);
- float b = blue(c);
- float h = hue(c);
- float s = saturation(c);
- float br = brightness(c);
- //println(br);
- if (h > 120 && h < 155 ) {
- primg.pixels[loc] = cTrans;
- }
- }
- primg.updatePixels();
- }
- background(100,0,0);
- image(primg, 0, 0);
- if(saved){
- PImage simg = createImage(primg.width,primg.height, RGB);
- simg = primg.get();
- if(outputOne){
- simg.save("img1.png");
- outputOne = false;
- }else{
- simg.save("img2.png");
- outputOne = true;
- }
- saved = false;
- }
- }
- update = false;
- }
- void keyPressed() {
- if (key == ' ') {
- if (captured == false) {
- img = cam;
- captured = true;
- update = false;
- saved = true;
- } else {
- captured = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment