Sunday 29 November 2009

The System Works!

After playing around with Processing for a few days with no success - trying to make webcam feeds appear when a certain switch is activated - I finally got my eureka moment! Instead of making a singular feed appear on the screen when a button is pressed, I could have all three feeds on at the same time, making two disappear (covering them with squares that are the same colour as the background) leaving a certain one on the screen - simple! The code for this program is below:

import processing.video.*;

Capture camera;
Capture camera2;
Capture camera3;

void setup()
{
size(1010, 730);
int value = 0;
// List all available capture devices to the console
// Use the information printed to the text area to
// correctly set the variable "s" below
println(Capture.list());

// Specify your own device by the name of the capture
// device returned from the Capture.list() function
camera = new Capture(this, width/3, height/3, "USB PC Camera-WDM");
camera2 = new Capture(this, width/3, height/3, "PC Camer@-WDM");
camera3 = new Capture(this, width/3, height/3, "Labtec WebCam-WDM");
// If no device is specified, will just use the default
//camera = new Capture(this, 320, 240, 12);

// Opens the settings page for this capture device
//camera.settings();
}


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

void draw()
{
image(camera, width/3, height/3);
image(camera2, 0, height/3);
image(camera3, 671, height/3);


if (keyPressed){
if (key == 'b' || key == 'B'){
rect(0, 0, width/3, height);
fill(0);
rect(width/3, 0, width/3, height);
fill(0);
}
}
if (keyPressed){
if (key =='t' || key == 'T'){
rect(width/3, 0, width/3, height);
fill(0);
rect(671, 0, width/3, height);
fill(0);
}
}
if (keyPressed){
{if (key == 'g' || key == 'G'){
rect(671, 0, width/3, height);
fill(0);
rect(0, 0, width/3, height);
fill(0);
}
}


}
}

The code is still a work in progress - trying to make it more slimline & efficient, but it works!
The screen shots are below.






No comments:

Post a Comment