We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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); }
Answers
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
"raster" is not really the right word for the effect you want. "half-toning" is closer. or "dithering". the second image you supply looks like an ordered dither with 8 or 16 levels.
but with one threshold you'll only ever separate the image into two colours, black and white.
please format your code. it's unreadable as it is.