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 & HelpPrograms › passing live video as variable
Page Index Toggle Pages: 1
passing live video as variable (Read 992 times)
passing live video as variable
May 27th, 2005, 7:44am
 
From:   dylan@thisisnotlondon.com
Subject: how to i set the video input to equal a variable in processing
Date: 27 May 2005 3:04:31 PM
To:   glen@glenmurphy.com

i need to declare the camera input as the video variable but not sure how

I have this which grabs my video

import processing.video.*;
Capture myCapture;

void setup()
{
 size(320, 240);
   String s = "QuickCam";
 myCapture = new Capture(this, s, width, height, 30);
}

void captureEvent(Capture myCapture) {
 myCapture.read();
}

void draw() {
 image(myCapture, 0, 0);
}



and this which analyses it

import processing.video.*;


int video_width  = 320;
int video_height = 240;
int num_pixels = (video_width * video_height);

//-------------------------------------------
void setup(){
 size(320, 240);
 beginVideo(video_width, video_height, 30);
}

//-------------------------------------------
void loop(){

 int black = color(0,0,0);                  // Declare some constants for colors.
 int white = color(255,255,255);
 int threshold = 127;
 
 int pix_val;                               // Declare variables to store a pixel's color.
 float pix_bri;
 
                                            // Split the image into dark and light areas:
 for (int i=0; i<num_pixels; i++){          // For each pixel in the video frame,
   pix_val = video.pixels[i];               // fetch the current color in that location,
   pix_bri = brightness (pix_val);          // and compute the brightness of that pixel.
                         
   if (pix_bri > threshold){                // Now "binarize" the video into black-and-white,
     pixels[i] = white;                     // depending on whether each pixel is brighter
   } else {                                 // or darker than a threshold value.
     pixels[i] = black;
   }
 }
                                            // Test a location to see where it is contained.
 int test_val = get (mouseX, mouseY);       // Fetch the pixel at the test location (the cursor),
 float test_bri = brightness (test_val);    // and compute its brightness.
 if (test_bri > threshold){                 // If the test location is brighter than threshold,
   fill (255,0,0);                          // draw a RED ellipse at the test location.
   ellipse (mouseX-10, mouseY-10, 20,20);
 } else {                                   // Otherwise,
   fill (0,255,0);                          // draw a GREEN ellipse at the test location.
   ellipse (mouseX-10, mouseY-10, 20,20);
 }

}

I just cant figure out how to get the two parts to talk to each other..all help appreciated

Dylan
Re: passing live video as variable
Reply #1 - May 27th, 2005, 11:32am
 
Hello man.. took the liberty to recode some of it.. and here's the working result (just one file):

Code:

import processing.video.*;
Capture myCapture;

void setup()
{
size(320, 240);
println(Capture.list()); // to output which cam is connected, then copy that text into the string below
String s = "Creative WebCam Live!-WDM";
myCapture = new Capture(this, s, width, height, 30);
}

void captureEvent(Capture myCapture) {
myCapture.read();
}

void draw() {
checkInput(myCapture.pixels);

}

//-------------------------------------------
void checkInput(color [] video){
PGraphics3 tmp = new PGraphics3(width,height,null);
int black = color(0,0,0); // Declare some constants for colors.
int white = color(255,255,255);
int threshold = 127;

int pix_val; // Declare variables to store a pixel's color.
float pix_bri;

// Split the image into dark and light areas:
for (int i=0; i<video.length; i++){ // For each pixel in the video frame,
pix_val = video[i]; // fetch the current color in that location,
pix_bri = brightness (pix_val); // and compute the brightness of that pixel.

if (pix_bri > threshold){ // Now "binarize" the video into black-and-white,
tmp.pixels[i] = white; // depending on whether each pixel is brighter
} else { // or darker than a threshold value.
tmp.pixels[i] = black;
}
}

image(tmp,0,0);
// Test a location to see where it is contained.
int test_val = get (mouseX, mouseY); // Fetch the pixel at the test location (the cursor),
float test_bri = brightness (test_val); // and compute its brightness.
if (test_bri > threshold){ // If the test location is brighter than threshold,
fill (255,0,0); // draw a RED ellipse at the test location.
ellipse (mouseX-10, mouseY-10, 20,20);
} else { // Otherwise,
fill (0,255,0); // draw a GREEN ellipse at the test location.
ellipse (mouseX-10, mouseY-10, 20,20);
}
}


this worked for me, hope it'll be as good to you Wink
Page Index Toggle Pages: 1