We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › Experimenting With Brightness Threshold
Page Index Toggle Pages: 1
Experimenting With Brightness Threshold (Read 1555 times)
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
   }
 }
}

Re: Experimenting With Brightness Threshold
Reply #1 - Mar 13th, 2010, 10:36am
 
Ian wrote on Mar 13th, 2010, 7:13am:
I get an error saying:

"texture() is not available with this renderer.
vertex(x, y, u, v) is not available with this renderer."

 size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480


size(640, 480) creates a 2D renderer. You need to use size(640, 480, P3D) or OPENGL (or possibly some other exotic ones from addon libraries such as p5sunflow).

-spxl
Re: Experimenting With Brightness Threshold
Reply #2 - Mar 15th, 2010, 1:51am
 
Thanks for your help, I'll give that a try. Does anybody have ideas on how I can show the regular webcam feed instead of black pixels. If I can get that working it would be great. Cheers!
Re: Experimenting With Brightness Threshold
Reply #3 - Mar 29th, 2010, 7:36am
 
Heya,
I'm also working on the same project but at the moment am trying to save out a movie clip of what the user is 'drawing' on the screen (using the above code). The MovieMaker example for DrawingMovie in Processing/Learning works fine but only once.
Is there any way to increment the name of the file being saved in this example? ie. drawing1.mov, drawing2.mov etc.

Here is the code:

Quote:
import processing.video.*;

MovieMaker mm;

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
  
    mm = new MovieMaker(this, width, height, "drawing.mov");
  
  strokeWeight(5); //change stroke size
  // 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 = 200; // 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
      }
    }
    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
    }
   
  }
  
    mm.addFrame();
}


void keyPressed() {
  if (key == ' ') {
    // Finish the movie if space bar is pressed
    mm.finish();
    // Quit running the sketch once the file is written
   // exit();
  }
}




Apologies if this is a stupid question and thanks in advance for any help!

Page Index Toggle Pages: 1