why the overlying cameras are blinking in the second window in Processing?

edited May 2015 in Questions about Code

Hi,guys, i just want to changing 2 cameras between each other, and the 2nd window will be showing as "present" window. But when the cameras overlying are blinking in the 2nd window, meanwhile the present window works well. If anyone can give a way to solve it, thanks!

here is the code:

import processing.video.*; 
import java.awt.Frame;


////////////////////////
PFrame f;
SecondApplet s;
////////////////////////



Capture cam1;   //camera 1 of present window
Capture cam2;   //camera 2 of present window
Capture Scam1;  //camera 1 of 2nd window
Capture Scam2;  //camera 2 of 2nd window




void setup(){


  size(600,600);
  PFrame f = new PFrame();



 String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam1 = new Capture(this, 720, 576);
    cam2 = new Capture(this, 720, 576);
     Scam1 = new Capture(this, 720, 576);
    Scam2 = new Capture(this, 720, 576);

  } if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam1 = new Capture(this, cameras[3]);
    cam2 = new Capture(this, cameras[3]);
    Scam1 = new Capture(this, cameras[3]);
    Scam2 = new Capture(this, cameras[3]);


    // Start capturing the images from the camera
    cam1.start();
    cam2.start();
    Scam1.start();
    Scam2.start();

  }



}


void draw(){


  if ((cam1.available() == true)) { 
    cam1.read();

    cam2.read();

    Scam1.read();

    Scam2.read();

  }
    image(cam1, 0,0,300,300 );  
    image(cam2, 150,150, 300,300 );


    s.image(Scam1, 0,0,300,300 );
    s.image(Scam2, 50,50, 300,300 );



}


public class PFrame extends Frame {

  public PFrame() {

    setBounds(0, 0, 600, 600);
    s = new SecondApplet();
    add(s);
    s.init();
    show();

  }

}


/////////////////////////Second Windows//////////////////////////////
/////////////////////////Second Windows//////////////////////////////


public class SecondApplet extends PApplet {



  public void setup() {

  }


  public void draw() {

  }

}

Tagged:

Answers

Sign In or Register to comment.