Raster image

edited March 2015 in How To...

Hello world! I'm trying to raster pictures from my webcam. Actually with this program, I have this kind of picture ( the first ). I wanna have more shades of grey (composed by dots), like the second one.

Could you help me, or redirected me to another discuss? i'm really lost...

Thanks!!

import processing.video.*; import controlP5.*;

Capture cam;

ControlP5 cp5; Slider abc;

float threshold = 75;

PImage destination;

int width_px = 320; int height_px = 240; int frame = 25;

int margin = 0; int margin_left = 60;

void setup() { size(200, height_px); noStroke(); cam = new Capture(this, width_px, height_px, frame); cam.start(); destination = createImage(cam.width, cam.height, RGB);

cp5 = new ControlP5(this);

// add a vertical slider cp5.addSlider("threshold") .setPosition(0,0) .setSize(200,15) .setRange(0,200) .setValue(128) ; }

void draw() { if(cam.available()) { cam.read(); } cam.loadPixels(); //image(cam, -margin_left ,margin); destination.loadPixels();

for (int x = 0; x < cam.width; x++) {
for (int y = 0; y < cam.height; y++ ) {
  int loc = x + y*cam.width;
  // Test the brightness against the threshold
  if (brightness(cam.pixels[loc]) > threshold) {
    destination.pixels[loc]  = color(255);  // White
  }  else {
    destination.pixels[loc]  = color(0);    // Black
  }
}

}

// We changed the pixels in destination destination.updatePixels(); // Display the destination image(destination,-margin_left,margin);

if ( keyPressed ) { saveFrame("knit-####.png"); } }

void slider(float theThreshold) { threshold = theThreshold; //println("setting threshold to "+theColor); }

audrey gisantfinal150

Answers

Sign In or Register to comment.