Ian
YaBB Newbies
Offline
Posts: 3
Experimenting With Brightness Threshold
Mar 13th , 2010, 7:13am
Hi, Im really new to Processing and have a few problems I cant seem to solve by myself. Im messing about with the brightness threshold example so I can kinda draw using different light sources. As you can see though I've added in code I found in another post to try and flip the video horizontally but it doesnt seem to work. I get an error saying: "texture() is not available with this renderer. vertex(x, y, u, v) is not available with this renderer." In the example all pixels below a certain threshold turn black and pixels above it turn white but i was wondering if theres a way for the black pixels to be fully see through or simply turned off so Im actually seeing a standard webcam feed with the white brighter pixels overlayed on top of it. I figure its simply a matter of telling the code not to turn the dark pixels black but I cant seem to do it. Any help would be greatly appreciated as Im trying to get this working for a college assignment but am pretty stuck at the moment. Thanks in advance for your help. import processing.video.*; color black = color(0,1); color white = color(255); int numPixels; Capture video; void setup() { size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 strokeWeight(5); // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 24); numPixels = video.width * video.height; noCursor(); smooth(); } void draw() { if (video.available()) { video.read(); video.loadPixels(); int threshold = 180; // Set the threshold value float pixelBrightness; // Declare variable to store a pixel's color // Turn each pixel in the video frame black or white depending on its brightness loadPixels(); for (int i = 0; i < numPixels; i++) { pixelBrightness = brightness(video.pixels[i]); if (pixelBrightness > threshold) { // If the pixel is brighter than the pixels[i] = white; // threshold value, make it white } else { // Otherwise, pixels[i] = black; // make it black } } beginShape(); texture(video); vertex(0,0,0,video.height); vertex(width,0,video.width,video.height); vertex(width,height,video.width,0); vertex(0,height,0,0); endShape(); updatePixels(); // Test a location to see where it is contained. Fetch the pixel at the test // location (the cursor), and compute its brightness int testValue = get(mouseX, mouseY); float testBrightness = brightness(testValue); if (testBrightness > threshold) { // If the test location is brighter than fill(black); // the threshold set the fill to black } else { // Otherwise, fill(white); // set the fill to white } } }